在VIM中,为什么光标移动4yk而不是4yj?

时间:2018-06-10 02:38:26

标签: vim neovim

要从当前位置+当前行向上拉4行,我可以使用4yk,并从当前位置+当前行向下划线4行,我可以使用4yj < / p>

4yk移动光标,而4yj则没有(至少在我正在使用的vim版本中,neovim)。

为什么会这样?

2 个答案:

答案 0 :(得分:5)

光标移动到动画的第一行。

使用4yk(或任何类似的向上运动),运动的第一行与当前行不同,因此光标移动。

使用4yj(或任何类似的向下运动),运动的第一行是当前行,因此光标不会移动。

来自:help operator

After applying the operator the cursor is mostly left at the start of the text
that was operated upon.  For example, "yfe" doesn't move the cursor, but "yFe"
moves the cursor leftwards to the "e" where the yank started.

答案 1 :(得分:0)

为了向下拉动,对您要问的问题的最佳解决方案是4yy。这样,它会抽取4行,加上任何CR,因此,如果您在两行之间放置,则会为您放置的内容留出空间。例如: 1 Shall I compare thee to a summer's day? 2 Thou art more lovely and more temperate: 3 Rough winds do shake the darling buds of May, 4 And summer's lease hath all too short a date: 5 Sometime too hot the eye of heaven shines, 6 And often is his gold complexion dimm'd; 7 And every fair from fair sometime declines, 8 By chance, or nature's changing course, untrimm'd; 9 But thy eternal summer shall not fade 10 Nor lose possession of that fair thou ow'st; 11 Nor shall Death brag thou wander'st in his shade, 12 When in eternal lines to time thou grow'st; 13 So long as men can breathe or eyes can see, 14 So long lives this, and this gives life to thee.

假设您将光标放在第5行,然后执行4yy,它将向下拉4行。然后,如果您(例如)转到12号行并按p(或转到13号行并按P,大写),则会得到: 1 Shall I compare thee to a summer's day? 2 Thou art more lovely and more temperate: 3 Rough winds do shake the darling buds of May, 4 And summer's lease hath all too short a date: 5 Sometime too hot the eye of heaven shines, 6 And often is his gold complexion dimm'd; 7 And every fair from fair sometime declines, 8 By chance, or nature's changing course, untrimm'd; 9 But thy eternal summer shall not fade 10 Nor lose possession of that fair thou ow'st; 11 Nor shall Death brag thou wander'st in his shade, 12 When in eternal lines to time thou grow'st; 13 **Sometime too hot the eye of heaven shines,** 14 **And often is his gold complexion dimm'd;** 15 **And every fair from fair sometime declines,** 16 **By chance, or nature's changing course, untrimm'd;** 17 So long as men can breathe or eyes can see, 18 So long lives this, and this gives life to thee. (星号显然是我的)。

4yj实际上不执行任何操作,因为正如romainl所说,第一行运动是当前行,因此光标不会移动。这就是为什么您必须使用4yy而不是4yj的原因。