Friday, April 25, 2008

Commenting out large code in VIM.

Whenever I need to comment out (C++ style comment //) a large codes in VIM editor, I usually comment out the first line and then go to the next line, then press '.' to repeat the same. But today I found another way to do the same.

Ctrl-v
96[ press down arrow key]
Shift-i
# or //
[Esc]

This puts the editor into visual block mode, jumps down 96 lines, puts the editor into insert mode, and then inserts whatever you typed at the beginning of all 96 selected lines. All in 9 key-presses. Not bad!

You can also uncomment with the following:

Ctrl-v
96[down]
x
[Esc]

Nice hacking .. let me know if there are any other ways to do the same ..