在vim中连接两行而不移动光标

cle*_*oux 6 vim

如何在vim中连接两行并将光标留在原始位置而不是跳转到合并点?

例如,将光标放在插入符指示的位置,取以下两行:

this is ^line one
this is line two
Run Code Online (Sandbox Code Playgroud)

合并J产品:

this is line one ^this is line two
Run Code Online (Sandbox Code Playgroud)

我该如何生产:

this is ^line one this is line two
Run Code Online (Sandbox Code Playgroud)

我尝试了CTRL-O各种各样的东西''.这些似乎都不起作用.它们到达行的开头,而不是原始光标位置.

Ran*_*ris 9

另一种不会踩踏标记的方法是这样的:

:nnoremap <silent> J :let p=getpos('.')<bar>join<bar>call setpos('.', p)<cr>
Run Code Online (Sandbox Code Playgroud)

更冗长,但它可以防止你失去一个标记.

  • :nnoremap - 非递归映射
  • <silent> - 按下映射时不要回显任何内容
  • J - 地图的关键
  • :let p=getpos('.') - 存储光标位置
  • <bar>- 命令分隔符(|用于地图,请参阅:help map_bar)
  • join - 正常的ex命令 J
  • <bar> - ......
  • call setpos('.', p) - 恢复光标位置
  • <cr> - 运行命令