Wednesday, January 9, 2008

VI editor: comment a whole line or N lines

If you want to comment N lines of a Bash script (for example) with the VI (or VIM) editor you have to type in ESC- mode (type ESC before typing the command):


:.,25s/^/# /

where ".,25s" stands for "from the current line to line number 25" and the sequence added to comment a line is "# " (hash plus a white space).
For a single line:

:11s/^/# /

for the 11th line or

:.s/^/# /

for the current line pointed by the cursor.



To uncomment:

:1,$s/^# //

where "$" stands for "last line", i.e. "from line 1 to the end of file".

0 commenti: