Skip to content

Instantly share code, notes, and snippets.

@ricardochimal
Created April 29, 2010 21:13
Show Gist options
  • Save ricardochimal/384258 to your computer and use it in GitHub Desktop.
Save ricardochimal/384258 to your computer and use it in GitHub Desktop.
" comment an entire visual block at once
" highlight the area however you want (V, CTRL+V) then
" ,c will comment the block
" ,u will uncomment the block
let b:comment_leader = '# '
au FileType haskell,vhdl,ada let b:comment_leader = '-- '
au FileType vim let b:comment_leader = '" '
au FileType c,cpp,java,php,js let b:comment_leader = '// '
au FileType sh,make,perl,ruby,python let b:comment_leader = '# '
au FileType tex let b:comment_leader = '% '
noremap <silent> ,c :<C-B>sil <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:noh<CR>
noremap <silent> ,u :<C-B>sil <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:noh<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment