vim block comment

Jan 07 2012 Published under Linux,Programming | Tags:

commenting a code block, add the following to .vimrc:

" , #perl # comments
map ,# :s/^/#/

" ,/ C/C++/C#/Java // comments
map  :norm!0i//  
map  :s/^ *\/\/ *//  :norm!=i{ 

" ,< HTML comment
map ,< :s/^\(.*\)$//:nohlsearch

" c++ java style comments
map ,* :s/^\(.*\)$/\/\* \1 \*\//:nohlsearch

usage:
highlight a block ctrl+v and type
,# for # comment
ctrl+m for // comment
shft+m for uncomment //
,< for comment
,* for /* */ comment

also I find this script useful:
http://www.vim.org/scripts/script.php?script_id=473

ref:
http://snippets.dzone.com/posts/show/194

Tags:

No responses yet

Comments are closed at this time.

Login