Jesse's Blog » 日志 » Comment/UnComment blocks in Vim
Comment/UnComment blocks in Vim
Jesse 发表于 2008-07-11 17:30:58
To comment/uncomment a block of lines in Vim, you can use the following setup in .vimrc. Vim already has several plugins for this, but I found this pretty skill in a reply to Tip #369, and I think it is just wonderful, simple and powerful. Thanks to d95mback AT dtek.chalmers.se (well, I cannot have this guy's name..)
au FileType haskell,vhdl,ada let b:comment_leader = '-- '
au FileType vim let b:comment_leader = '" '
au FileType c,cpp,java let b:comment_leader = '// '
au FileType sh,make 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>
Then,
,c comments out a region (or the current line)
,u uncomments a region
----------------------------------------
Incidentally, to apply to Python files, add *python* to the 'sh,make' line, not py(!). I spent some(!) time here, 'cause py doesn't work out.
Jesse
au FileType haskell,vhdl,ada let b:comment_leader = '-- '
au FileType vim let b:comment_leader = '" '
au FileType c,cpp,java let b:comment_leader = '// '
au FileType sh,make 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>
Then,
,c comments out a region (or the current line)
,u uncomments a region
----------------------------------------
Incidentally, to apply to Python files, add *python* to the 'sh,make' line, not py(!). I spent some(!) time here, 'cause py doesn't work out.
Jesse
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
