1. :x,y s/^/# /
The colon is command mode, obviously
x and y is a range of line numbers you want to affect
s is a sed substitution, the caret (^) means the beginning of the line
The sharp (#) is the comment character, again obviously
I put a space after the comment, but it isn't necessary, substitute any string that suits you.
2. Another way to do do this is to visually select the lines you want to comment with shift-v and up and down arrows, then type
:s/^/# /
Easier for blocks of fewer lines.
NB: When you press : vim will add '<,'> to the command line so the final command is:
:'<,'>s/^/# /
9/22/10
vi editor: multiline comment
Labels:
vi
Subscribe to:
Post Comments (Atom)
2 comments:
Nice site, Thanks.
nexpro nexium
It is very helpful!
Post a Comment