Vim 从当前到第 n 行(包括第 n 行)

发布于 2025-01-18 05:52:29 字数 397 浏览 0 评论 0原文

在vim 中,nyy将拉动n行。这意味着它将拉动所有线路,包括当前线和(N-1)线。是否有一个命令,我可以将所有线与电流和第n行的夹杂着 - >拉紧n+1行?

如果是这样,一个人可以将nyy命令覆盖到VIMRC中的此命令吗?

背景:我已经设置了编辑器,以向我展示相对于我所在的行号。这对于导航非常方便,例如2J将光标设置为2。每次。

In vim nyy will yank n lines. This means it will yank all the lines including the current line and the (n-1)th line. Is there a command with which I can yank all the lines inlcuding the current and the nth line -> yanking n+1 lines?

If so could one override the nyy command to this command in vimrc?

Background: I have my editor set up to show me the line number relative to the one I am at. This is convenient for navigation e.g. 2j sets the cursor to the line with the 2. When I use 2yy however it yanks all the lines excluding the one with the 2 which trips me up every time.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

旧人九事 2025-01-25 05:52:29

请注意,您的屏幕截图不是 Vim 屏幕截图,这意味着您获得的有关 Vim 的任何建议可能会或可能不会在您使用的 Vim 模拟器中起作用。

无论如何,2j2yy 中的 2 是一个计数,根据类型的不同,它可以产生不同的效果您使用它的命令。

2j 中,它的字面意思是“执行 j 两次”,它告诉 Vim 将光标向下移动两行。 2j 是一个动作。

在 2yy 中,它的字面意思是“在这一行和下一行上执行 yy”,它告诉 Vim 要复制多少行,包括当前行。这意味着“每次都会让你绊倒”的行为是完全正常的、一致的和预期的。

那不是你想要的。

Vim 从当前到第 n 行(包括第 n 行)复制

您真正想要的是使用已有的向下运动 2jy 运算符: y2j< /代码>。

请参阅:帮助运算符

Note that your screenshot is not a Vim screenshot, which means that whatever advice you may get regarding Vim may or may not work in the Vim emulator you use.

Anyway, the 2 in 2j and in 2yy is a count, which can have varying effects depending on what kind of command you use it with.

In 2j, it literally means "do j two times", which tells Vim to move the cursor two lines downwards. 2j is a motion.

In 2yy, it literally means "do yy on this line and the next one", which tells Vim how many lines to to yank, including the current one. It means that the behaviour that "trips you up every time" is perfectly normal, consistent, and expected.

That's not what you want.

Vim yank from current to nth line including nth line

What you actually want is to use the downwards motion you already have, 2j, with the y operator: y2j.

See :help operator.

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