So part of anyone’s programming process is commenting and un-commenting blocks or lines of code. To comment and un-comment with “//” style comments in Vim using ./ and .? as your hot keys, respectively, put this in your ~/.vimrc:
map ./ :s/^\(\s*\)/\1\/\//<CR>
map .? :s/^\(\s*\)\/\//\1/<CR>
type ./ to comment
type .? to uncomment
“//” style comments cover C99, C++, PHP, Java, and a variety of other languages with C-like syntax.
The (\s*\) bit captures any whitespace at the beginning of the line, so your tab formatting doesn’t get messed up.
Remember, once you’ve made a selection in visual mode, you can always type “gv” to make the selection again.
One more thing: to quickly select an entire line in Vim, Shift+V. You can comment and uncomment individual lines in a flash with vim. Optimal.
Vim rules.
Comment [554]