Yank n向上排列而不移动

Tim*_*Tim 12 vim

在不移动光标的情况下向下划线7行,我可以7yy.是否可以向上执行相同操作,而不是使用宏或重新映射?

Pet*_*ker 29

您可以使用:yank带有范围的命令来完成此效果.

:.-6,.yank
Run Code Online (Sandbox Code Playgroud)

范围说明:

  • . 或点表示当前行
  • .-6 表示当前行减去6
  • .-6,. 是当前行减去6的当前行
  • 这可以缩写.-6为仅仅-6给我们-6,.yank
  • 当前行也假设在范围的末尾 -6,yank
  • yank命令可以缩短为仅仅:y给我们-6,y

最终命令:

:-6,y
Run Code Online (Sandbox Code Playgroud)

如需更多帮助:

:h :yank
:h [range]
Run Code Online (Sandbox Code Playgroud)


Fel*_*ing 6

您可以执行以下操作:

6yk6j
Run Code Online (Sandbox Code Playgroud)

这将会拉动前面的6行和当前的行,但是courser会移动.6j跳回到上一个位置.

  • 这将猛拉7 + 1行(当前行也是.)7应为6. (2认同)

sid*_*yll 6

你可以简单地猛拉到运动,然后返回游标使用无论是位置'[还是'].

6线的冲击加上当前总共7个:

y6u
Run Code Online (Sandbox Code Playgroud)

然后,使用一些鲜为人知的标记:

'[ -> to the first character on the first line of
      the previously yanked text (or changed)
`[ -> to the first character of the previously yanked text
'] -> to the first character on the last line of yanked text
`] -> to the last character of the preciously yanked text
Run Code Online (Sandbox Code Playgroud)

所以:

y6u']
y6u`]
Run Code Online (Sandbox Code Playgroud)

根据您的具体需求,您可以使用两种解决方案.前者将光标移动回的第一个字符就行了你的光标是,后者移动到该行的最后一个字符.

但还有另一个标记可能很方便:'^.它表示离开插入模式时光标的最后位置.

'^ -> moves to the beginning of the last line when leaving insert mode.
`^ -> moves to the exact position where insert mode was last left.
Run Code Online (Sandbox Code Playgroud)

然后这是另外两个解决方案:

y6u'^
y6u`^
Run Code Online (Sandbox Code Playgroud)

那不是结束!如果您假装继续插入文本,则可以使用该gi命令.它会移动到`^标记并进入插入模式.然后我们有第五个解决方案:

y6ugi
Run Code Online (Sandbox Code Playgroud)

我希望其中一个满足您的需求!