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?
\_.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With