在 VIM 中猛拉某个区域而不将光标移动到块的顶部?
是否有一种简单的方法(即无需编写脚本或复杂的键盘映射序列)来 Yank 一组行并将光标保留在执行 Yank 的位置(而不是在块的开头)?
根据 VIM 的帮助:“请注意,在按字符复制命令之后,Vim 会将光标保留在距离缓冲区开头最近的第一个复制字符上。”逐行似乎表现类似。
这对我来说有点烦人,因为我倾向于从上到下选择一个大区域,进行猛拉,然后粘贴到所选区域底部附近或下方。今天,我在 Yank 之前设置了一个标记 (mx),然后跳回来,但我怀疑可能有一个不同的 Yank 序列可以满足我的需要。
我已经在 SO 和网络上搜索过很多次了。有太多现有的“VIM 快捷方式”材料需要翻阅,但我还没有找到解决方案。
提前致谢。
Is there a simple way (i.e. without writing a script or elaborate keymap sequence) to Yank a group of lines and leave the cursor wherever the Yank was performed, as opposed to at the start of the block?
According to VIM's help: "Note that after a characterwise yank command, Vim leaves the cursor on the first yanked character that is closest to the start of the buffer." Line-wise seems to behave similarly.
This is a bit annoying for me since I tend to select a large region from top to bottom, Yank, and then paste near or below the bottom of the selected region. Today I'm setting a mark (m-x) just before Yank and then jumping back, but I suspect there may be a different Yank sequence that will do what I need.
I've searched SO and the web for this numerous times. There is so much existing "VIM shortcuts" material to wade through yet I've not found a solution to this one yet.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
不太回答您的问题,但也许
']
可以解决您的问题?Not quite answering your question, but perhaps
']
would solve your problem?如果您使用可视块 (
v
),那么在拉出该块后,您可以使用gv
重新选择同一块(这也会将光标位置移回到猛拉之前的位置)。如果随后按 Esc 键,则无需移动光标即可取消选择该块。同样令人感兴趣的可能是可视块模式下的 ctrl-o 命令,该命令在所选块的开头和结尾之间跳转。
If you're using visual blocks (
v
), then after yanking the block you can usegv
to re-select the same block (which also moves your cursor position back to where it was before yanking). If you then press Esc, the block is un-selected without moving the cursor.Also of interest might be the
ctrl-o
command in visual block mode, which jumps between the start and end of the selected block.如果在视觉模式下拉动,您还可以使用
'>
或`>
转到刚刚拉动的视觉选择的最后一行/字符。在这种情况下,这本质上与']
和`]
相同,这显然在 VsVim 等中不受支持。If yanking in visual mode, you could also use
'>
or`>
to go to the last line/character of the just yanked visual selection. In this context this is essentially the same as']
and`]
which is apparently not supported e.g. in VsVim.:y3
将从当前当前行中拉出三整行,如果您确切知道要拉动多少行,这个命令非常方便。:help :yank
了解详细信息。:%y
将选择整个缓冲区而不移动光标,像
ggvG$y
一样,没有选择突出显示的闪烁和修改"*
寄存器。我使用这个插入模式映射:
ps:如果你喜欢
;
要粘贴(在 vim 之外),请使用%y+
检查 https://stackoverflow.com /a/1620030/2247746
:y3
will yank three whole lines from current current line, If you know exactly how many line to yank, this command is very handy.:help :yank
for details.:%y
will select the whole buffer without moving the cursor,like
ggvG$y
, without the flash of selection highlight and modifying the"*
register.I use this insert mode map:
ps: if you prefer
<C-V>
to paste(outside vim), use%y+
check https://stackoverflow.com/a/1620030/2247746
我不确定自
vmap ygv
解决方案发布以来 YankRing 是否发生了变化,但在将其添加到我的.vimrc
后,这种情况并没有持续存在。 YankRing 实际上覆盖了它。这是我在
.vimrc
中的解决方案。I'm not sure sure if YankRing has changed since the
vmap ygv<Esc>
solution was posted but that didn't persist for me after adding it to my.vimrc
. YankRing actually overwrote it.Here's my solution in
.vimrc
.我不知道同时发生了什么,但在 IdeaVim 中,接受的答案并不像我希望的那样工作。 (不要将光标移到猛拉上)
对我来说,诀窍就是在猛拉之前设置一个标记,然后再进行猛拉。
I don't know what happened in the meantime but in IdeaVim the accepted answers don't work as I'd like them to. (Don't move the cursor on yank)
For me what did the trick was just setting a mark before yank and go to that afterwards.
如果您使用 Lua,您可以定义此键绑定,这将拉动并返回到拉动之前的位置:
If you are using Lua, you can define this keybinding, this will yank and go back to position before yanking:
使用
ModeChanged
事件和vim.v.operator
变量。Use the
ModeChanged
event andvim.v.operator
variable.