Почему в VIM курсор перемещается с 4yk, а не с 4yj? - PullRequest
0 голосов
/ 10 июня 2018

Чтобы восстановить 4 строки вверх от текущей позиции + текущая строка, я могу использовать 4yk, а чтобы восстановить 4 строки вниз от текущей позиции + текущая строка, я могу использовать 4yj

Но 4yk перемещает курсор, тогда как 4yj - нет (по крайней мере, в версии vim, которую я использую, neovim).

Почему это так?

Ответы [ 2 ]

0 голосов
/ 24 июня 2018

Для того, чтобы дергать вниз, лучшим решением будет 1001 *.Таким образом, он вытягивает 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.

0 голосов
/ 10 июня 2018

Курсор перемещается на первую строку движения.

При 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.
...