分页: 1 / 1
请问Vim如何注释掉一段 c 代码
发表于 : 2008-08-10 17:32
由 nickleeh
如题:怎样在 Vim 中注释/反注释掉一段 c 代码?
发表于 : 2008-08-10 17:38
由 kofshower
自己写一个函数
参考代码:
代码: 全选
function! CPP_CodeComment( mode, style )
if a:mode=="a"
if a:style == 'yes'
silent exe ":s#^#/\* #"
silent put = ' */'
else
silent exe ":s#^#//#"
endif
endif
if a:mode=="v"
if a:style == 'yes'
silent exe ":'<,'>s/^/ \* /"
silent exe ":'< s'^ '\/'"
silent exe ":'>"
silent put = ' */'
else
silent exe ":'<,'>s#^#//#"
endif
endif
endfunction
发表于 : 2008-08-10 17:55
由 nickleeh
谢谢楼上的回复。
我找到了一个非常好的插件,解决这个问题:
http://www.vim.org/scripts/script.php?script_id=1173
非常方便,可以用gc来注释/反注释文本块。(不仅支持c,还支持 TeX/ruby/python/perl
regions in vim scripts, HTML or JavaScript in php code ... .... 推荐大家试一下)
发表于 : 2008-08-10 23:06
由 ccbrighty
发表于 : 2008-08-10 23:13
由 eexpress
EnhancedCommentify.vim
发表于 : 2008-08-16 11:31
由 zcg0696
发表于 : 2008-08-16 13:00
由 sirxenofex
ctrl+v进入块选择模式,然后选定要注释的若干行,按I(大写)进入插入模式,在行首插入#,再按Esc退出插入,再按一次退出块选择就行了。如果是反注释,进入块选择后选定若干行首的#再删掉就行了。
Re:
发表于 : 2008-11-15 19:05
由 wangtwo
zcg0696 写了:手动
修改下'#'可以对付其它的注释符
sirxenofex 写了:ctrl+v进入块选择模式,然后选定要注释的若干行,按I(大写)进入插入模式,在行首插入#,再按Esc退出插入,再按一次退出块选择就行了。如果是反注释,进入块选择后选定若干行首的#再删掉就行了。
佩服