我想使用vim删除以下代码段中的所有注释。请帮助我。
int main()
{
Computer compute;
// To create an 'instance' of the class, simply treat it like you would
// a structure. (An instance is simply when you create an actual object
// from the class, as opposed to having the definition of the class)
compute.setspeed ( 100 );
// To call functions in the class, you put the name of the instance,
// a period, and then the function name.
cout<< compute.readspeed();
// See above note.
}
答案 0 :(得分:3)
:g/<Pattern>/d
它将删除与<Pattern>
匹配的所有行。例如
:g/\s*\/\//d
将删除所有前两个非空白字符为//
的行。
答案 1 :(得分:0)
有几种方法可以做到这一点。
最简单的可能是使用插件,例如NERDCommenter http://www.vim.org/scripts/script.php?script_id=1218
如果您不想安装内容,则可以使用可视模式:
- Ctrl + V
进入列可视模式
- 选择//
- 然后x
你也可以使用宏和qa
,然后删除第一行的//
,用q
关闭录制,然后重播宏@a
。
最后,如果您是正则表达式粉丝,那么您可以执行此操作::g/\s*\/\//d