Комментирование XML в энергии

Могут ли некоторые из ваших зависимостей быть статически связаны?

19
задан Robert Munteanu 1 June 2009 в 08:31
поделиться

5 ответов

You can use a combination of matching XML tags, as can be seen in this question and Perl's search and replace.

For instance, given this snippet:

<TypeDef name="a">
  <ArrayType high="14" low="0">
    <UndefType type="node">
    </UndefType>
  </ArrayType>
</TypeDef>

Put the cursor on either the opening or closing TypeDef and type the following sequence:

vat:s/^\(.*\)$/<!--\1-->/

v - puts you into visual mode
at - selects the whole XML tag
:s/^\(.*\)$// - surrounds each line with '', the comment delimiters for XML

Alternatively, you can just delete it like this:

dat

d - delete according to the following movements
at - as before

16
ответ дан 30 November 2019 в 03:48
поделиться

Vim doesn't have smart commenting for all file types by itself. You should get a script for your commenting needs.

I use the enhcomentify script which has been around and maintained for a long time

http://www.vim.org/scripts/script.php?script_id=23

It seems to do xml well and you get the advantage of the same key bindings for any filetype you are using.

There are others.. notably the NERD Commenter

http://www.vim.org/scripts/script_search_results.php?keywords=comment&script_type=&order_by=rating&direction=descending&search=search

5
ответ дан 30 November 2019 в 03:48
поделиться

Best it'd be if you'd find a command that adds things in the beginning and end of the selection.

When I'm commenting python code, I'm doing this:

:2,4s/^/#/g
1
ответ дан 30 November 2019 в 03:48
поделиться

используйте Surround.vim для общего сопоставления тегов, удаления, вставки, окружения и т. Д.

Для комментирования тегов легко использовать текстовые объекты vim и простой макрос

Пример:

введите

vmap ,c <esc>a--><esc>'<i<!--<esc>'>$

в подходящее место, затем поместите курсор на заглавную букву «A» в «ArrayType» во второй строке следующего (заимствовано из приведенного выше примера Натана Фельмана)

<TypeDef name="a">
  <ArrayType high="14" low="0">
    <UndefType type="node">
    </UndefType>
  </ArrayType>
</TypeDef>

, затем нажмите

vat,c

и вы получите:

<TypeDef name="a">
  <!--<ArrayType high="14" low="0">
    <UndefType type="node">
    </UndefType>
  </ArrayType>-->
</TypeDef>

с курсором в конце комментария

5
ответ дан 30 November 2019 в 03:48
поделиться

Я думаю, что адаптация этой подсказки vim может быть полезной.

Я предлагаю добавить:

" Wrap visual selection in an XML comment
vmap <Leader>c <Esc>:call CommentWrap()<CR>
function! CommentWrap()
  normal `>
  if &selection == 'exclusive'
    exe "normal i-->"
  else
    exe "normal a-->"
  endif
  normal `<
  exe "normal i<!--"
  normal `<
endfunction

в ваш .vimrc

Затем с визуальным выделением active (V), нажмите \ c (обратная косая черта, затем c), чтобы заключить блок в комментарии в стиле XML.

В качестве альтернативы, как предложено в вики, вы можете поместить код в ~ / .vim / scripts / wrapwithcomment.vim и добавьте в свой .vimrc:

au Filetype html,xml source ~/.vim/scripts/wrapwithcomment.vim

, чтобы эта функция загружалась только при работе с файлом html или xml.

2
ответ дан 30 November 2019 в 03:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: