我想这样做:
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
转换为VISUAL
模式,可以选中文本,按d
可以剪切文本,但是如何插入被剪切并插入新行的文本?有什么命令吗?
而且我认为在剪切文本之后,您可以按 o
并按 esc
并按 p
进行粘贴,但似乎乏味。有没有更好的命令?
提前致谢!
最佳答案
如果你想保存击键,你可以插入 "
使用 <c-r>"
在插入模式下注册.
您也可以使用 D
从光标处删除到行尾,它将删除的部分放在 "
中登记。
因此,如果您的光标位于评论的第一个字符上,您可以使用
DO<c-r>"
转化为
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>
在插入模式下。
关于vim如何剪切文本并插入新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32961285/