Tuesday, April 14, 2009

Commenting and Uncommenting lines in VI

Commenting and un-commenting lines in VI is a task encountered frequently in my job.
So i came up with a simple macro which will do it two concurrent keystrokes.

Add this to you .vimrc file

map \\ I#
map \] ^x


With this in your rc file, you can comment line by pressing "\" and "\".
To un-comment, press "\" and "]". I found these key combinations best suited for me. But you can change the second keystroke according to your needs.

Saves time for me, hope helps others.

Note: Verified with Gnu Vim.