我想这样做:
1 printf("hello world\n");
2 bool func() //I want to cut the comment and insert between line 1 and line 2
3 {
4 //to do
5 }
而且,我希望在//
之后剪切评论并在第1行和第2行之间插入。我知道,使用Ctrl+v
,vim
会转换为{{1}您可以选择文本,然后按VISUAL
,您可以剪切文本,但如何插入要剪切的文本并插入新行?有命令吗?
我认为在剪切文本后,您可以按d
并按o
然后按esc
进行粘贴,但这似乎很乏味。有没有更好的命令?
提前谢谢!
答案 0 :(得分:5)
如果要保存击键,可以使用"
在插入模式下插入<c-r>"
寄存器。
此外,您可以使用D
从光标删除到行尾,将删除的部分放在"
寄存器中。
因此,如果您的光标位于评论的第一个字符上,您可以使用
DO<c-r>"
to transfrom
printf("hello world\n");
bool func() //I want to cut the comment and insert between line 1 and line 2
{
//to do
}
向
printf("hello world\n");
//I want to cut the comment and insert between line 1 and line 2
bool func()
{
//to do
}
您需要做的就是在func()
之后清理尾随空格。
请查看:help i_CTRL-R
以了解有关插入模式中<c-r>
的更多信息。
答案 1 :(得分:1)
除了FDinoff建议的解决方案之外的另一个解决方案:
在第一个斜线处D (将评论剪切到行尾)
并运行:pu!
(将内容放在当前行之上。)