Vim 在视觉模式下对相对范围进行操作的最佳方式是什么?
我经常使用这样的方法来删除、复制和粘贴:
:3,6y
从 Vim 7 开始,我改用相对行号。我发现通过 h,j,k,l 等命令使用相对行编号要容易得多。
自从切换到相对行编号后,我发现很难在绝对范围上进行操作(例如。>:3,6y
)。由于 Vim 显示的是相对行号,所以我花了很长时间来确定需要选择哪些绝对行号。
如果您的设置显示相对行编号,那么在范围内使用视觉选择的最佳/最快方法是什么?天真地,我正在寻找类似的东西:
:-2,+8y
(yank the lines from 2 lines above my current position to
8 lines below my current position.)
I often delete, yank, and paste using something like this:
:3,6y
Since Vim 7, I've switched to using relative line numbers. I find it's much easier to use relative line numbering with commands like h,j,k,l
etc.
Since switching to relative line numbering, I find it difficult to operate on absolute ranges (eg. :3,6y
). It takes me too long to determine what absolute line numbers I need to select since Vim is displaying relative line numbers.
What is the best/quickest way to use visual selection on a range if your setup is displaying relative line numbering? Naively, I'm looking for something like:
:-2,+8y
(yank the lines from 2 lines above my current position to
8 lines below my current position.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过你天真的事情吗?
:-2,+8y
相当于:.-2,.+8y
并且应该做你想要的。请注意,如果您不指定数字,则假定
1
,因此::,+y
表示.,.+1 y
:拉出当前行和下一行。在
:help range
上,它没有得到很好的解释。相关部分在这里:文档没有告诉的是,如果
+
r-
前面没有任何内容,则假定.
。Did you try your naive thing?
:-2,+8y
is equivalent to:.-2,.+8y
and should do what you want.Note that if you don't specify a number,
1
is assumed, so::,+y
means.,.+1 y
: yank current and next line.On
:help range
it is not well explained. The relevant parts are here:What the doc does not tell is that if the
+
r-
is not preceded with anything,.
is assumed.