From Wiki

Vim: CommentingOutARangeOfLines

Tip #981: Commenting out a range of lines

Whatever method you use to find the line numbers they can be used as a range for a substitute:

:xx,yy s/^/# /

Move to the first line and set a mark with: ma (where "a" is any letter you choose) Move to the last line and issue the following ex:

:'a,. s/^/# /

More elaborate sequences of pure old ex commands can also be used to create boxes around C/C++ blocks; but they are really horrid to type every time so they have to be mapped to some key sequence and entails consistently using the same register every time.

For example:

 
map  gC :'a,. s/^/ */^M:.
s/\(.*\)/\1^V^V^M **************\//^M:'a
s/\(.*\)/\/**************^V^V^M\1/^M

maps the sequence gC to a macro which wraps a block of text, from the current line back to the line marked by the "a" in a C style comment like:

 /************************
  *
  * ....
  * ....
  ************************/

Retrieved from http://kozgun.net/wiki/pmwiki.php?n=Vim.CommentingOutARangeOfLines
Page last modified on September 03, 2005, at 04:35 PM