Vim 从当前到第 n 行(包括第 n 行)
在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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,您的屏幕截图不是 Vim 屏幕截图,这意味着您获得的有关 Vim 的任何建议可能会或可能不会在您使用的 Vim 模拟器中起作用。
无论如何,
2j
和2yy
中的2
是一个计数,根据类型的不同,它可以产生不同的效果您使用它的命令。在
2j
中,它的字面意思是“执行j
两次”,它告诉 Vim 将光标向下移动两行。2j
是一个动作。在 2yy 中,它的字面意思是“在这一行和下一行上执行 yy”,它告诉 Vim 要复制多少行,包括当前行。这意味着“每次都会让你绊倒”的行为是完全正常的、一致的和预期的。
那不是你想要的。
您真正想要的是使用已有的向下运动
2j
和y
运算符: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
in2j
and in2yy
is a count, which can have varying effects depending on what kind of command you use it with.In
2j
, it literally means "doj
two times", which tells Vim to move the cursor two lines downwards.2j
is a motion.In
2yy
, it literally means "doyy
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.
What you actually want is to use the downwards motion you already have,
2j
, with they
operator:y2j
.See
:help operator
.