Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - Deleting XML Comments

Tags:

vim

xml

How do I delete comments in XML?

If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread across many lines?

like image 877
Vijay Dev Avatar asked Nov 12 '09 14:11

Vijay Dev


1 Answers

\_. instead of . allows matching on all characters including newlines. But that alone will cause the regex engine to go overboard since regexes are greedy by default. Use \{-} instead of * for a non-greedy match all.

Since the g/ /d command only deletes a single line (even for a multiline match), it would be preferable to switch to s/ / /g (substitute global).

:%s/<!--\_.\{-}-->//g

like image 145
fengb Avatar answered Oct 03 '22 01:10

fengb