Monday, November 19, 2007

Comment a block of source code using Vim editor

To easily comment a block of source code using Vim editor do following:
  1. Enter the block-wise visual mode (using ctrl+v command) and select desired block with h, j, k and l keys. Selecting the most left columns of the lines that you want to comment is sufficient, as well.
  2. Type shift+i to enter insert mode and move cursor to the beginning of the first line in selected block.
  3. Type // if you want to add C line comments (#, ", etc. depending of the used programming language syntax).
  4. Type Esc to leave the visual mode.
Characters (from step 3) will be added at the beginning of every line in the block.


The block-wise visual mode can be also used in other situations. For example, if you want to add certain text in the middle of several adjacent lines you should do previously explained routine on the block which begins at the position where you want to insert the text.

Enjoy using Vim editor.

No comments: