vim如何剪切文本并插入新行

Goi*_*Way 2 vim

我想做这个:

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 }
Run Code Online (Sandbox Code Playgroud)

而且,我希望//在第1行和第2行之间剪切注释和插入.我知道,通过使用Ctrl+v,vim转换为VISUAL模式,你可以选择文本,按下d,你可以剪切文本,但如何我可以插入要剪切的文本并插入新行吗?有命令吗?

我认为在剪切文本后,您可以按o,然后按esc,然后按p粘贴,但这似乎很乏味.有没有更好的命令?

先感谢您!

FDi*_*off 5

如果要保存击键,可以"使用在插入模式下插入寄存器<c-r>".

您也可以从光标删除到行的末尾,D将删除的部分放在"寄存器中.

因此,如果您的光标位于您可以使用的注释的第一个字符上

DO<c-r>"
Run Code Online (Sandbox Code Playgroud)

来自

printf("hello world\n");
bool func() //I want to cut the comment and insert between line 1 and line 2
{
    //to do
}
Run Code Online (Sandbox Code Playgroud)

printf("hello world\n");
//I want to cut the comment and insert between line 1 and line 2
bool func() 
{
    //to do
}
Run Code Online (Sandbox Code Playgroud)

您所要做的就是清理后面的空白区域func().


看看:help i_CTRL-R有关<c-r>插入模式的更多信息.