Vim 在视觉模式下对相对范围进行操作的最佳方式是什么?

发布于 2024-12-12 04:18:30 字数 414 浏览 0 评论 0原文

我经常使用这样的方法来删除、复制和粘贴:

: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听你说爱我 2024-12-19 04:18:30

你尝试过你天真的事情吗?

:-2,+8y 相当于 :.-2,.+8y 并且应该做你想要的。

请注意,如果您不指定数字,则假定 1,因此: :,+y 表示 .,.+1 y:拉出当前行和下一行。

:help range 上,它没有得到很好的解释。相关部分在这里:

Line numbers may be specified with:     *:range* *E14* *{address}*
    [...]
    .       the current line              *:.*
    [...]
Each may be followed (several times) by '+' or '-' and an optional number.
This number is added or subtracted from the preceding line number.  If the
number is omitted, 1 is used.

文档没有告诉的是,如果 + 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:

Line numbers may be specified with:     *:range* *E14* *{address}*
    [...]
    .       the current line              *:.*
    [...]
Each may be followed (several times) by '+' or '-' and an optional number.
This number is added or subtracted from the preceding line number.  If the
number is omitted, 1 is used.

What the doc does not tell is that if the + r - is not preceded with anything, . is assumed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文