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.

2 comments:

Mukesh Chuahan said...

Good start Punit. :-)

hiteshsjoshi said...

Ya, Good Start Punit. I have added your blog as a link from mine.

As far as this post is concerned, there are many more macros that you can add to your vimrc file.
I remember adding macros like "for (i=0;;i++)", "while(i)" and others. Turned out to be useful initially but then I did not use the VIM editor frequently :(