首页 > 解决方案 > Vim - jump back to previous position when moving multiple lines at once

问题描述

When I use Vim, I often times use motions commands when moving lines.
For example if I want to move 20 lines down, I press 20j.
Now after having "jumped" 20 lines down, if I want to go back again to my previous position, I have to enter 20k.

Is there a way to jump to my previous position without typing 20k?
For example, by somehow adding the previous position to Vims jump list, then I could use <c-o> to jump back.

(By the way, I only want to jump back when I move more that one line at once).

标签: listvimline

解决方案


这里的问题是,jk不是“跳跃”。当你这样做时,20j你真的在​​做jjjjjjjjjjjjjjjjjjjj,但速度很快,所以你必须将这些任意动作转化为适当的跳跃<C-o>才能工作。如何做到这一点在下面解释:help jumplist

您可以通过使用“m”设置'标记来显式添加跳转。

在实践中:

m'20j

然后<C-o>''``返回。

不过,还有一些更聪明的移动方式,不需要你计算行数,而且是实际的跳跃,比如:help /and :help ?


推荐阅读