How to append chars except empty and comment-out lines via VIM?

65 views Asked by At

For example,

#LINE0
LINE1
LINE2

LINE3

append DEBUG =>

#LINE0
LINE1 DEBUG
LINE2 DEBUG

LINE3 DEBUG
3

There are 3 answers

1
Amadan On
:%s/\(.\+\)/\1 DEBUG/

In all lines, replace the string of at least one character with that string followed by DEBUG.

0
lcd047 On

Use the :global command:

:%g!/\v^%(\s*\#|$)/ s/$/ DEBUG/

See :help :global for details.

0
SergioAraujo On

Using global command makes it easier:

:g/./normal A DEBUG

Explanation:

: ................ command
g ................ global
/ ................ start search
. ................ any char
/ ................ end of search
normal ........... do the global command in normal mode
A ................ start appending mode (insert)
<space>DEBUG ..... what you need :)