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

In VIM, why does the cursor move with 4yk but not 4yj?

从当前位置+当前行向上拉4行,我可以使用4yk,从当前位置+当前行向下拉4行,我可以使用4yj

但是 4yk 移动光标,而 4yj 不移动(至少在我使用的 vim 版本中,neovim)。

这是为什么?

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

使用 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.

为了向下猛拉,您所问的最佳解决方案是 4yy。这样,它会拉出 4 行,加上它会解释任何 CR,因此如果您在两行之间放置,它会为您放置的内容生成 space。例如: 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.