Put this in your .vimrc:
map <F5> :s.^//.. <CR> :noh <CR> map <F6> :s.^.//. <CR> :noh <CR>
Now you use a visual line select (shift-V
) to select what you want to comment,
smack F5
and it's done. F6
uncomments.
As a bonus, use these to change indents. Change indent to your preference for
indenting. I use 4 spaces. Use \t
if you want a tab. Combined with shift-V
, you
can move whole blocks left and right easily.
map <F7> :s/^indent// <CR> :noh <CR> gv map <F8> :s/^/indent/ <CR> :noh <CR> gv