northtree
northtree

Reputation: 9255

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

For example,

#LINE0
LINE1
LINE2

LINE3

append DEBUG =>

#LINE0
LINE1 DEBUG
LINE2 DEBUG

LINE3 DEBUG

Upvotes: 1

Views: 40

Answers (3)

SergioAraujo
SergioAraujo

Reputation: 11800

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 :)

Upvotes: 0

lcd047
lcd047

Reputation: 5851

Use the :global command:

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

See :help :global for details.

Upvotes: 2

Amadan
Amadan

Reputation: 198324

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

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

Upvotes: 1

Related Questions