如何防止在 Vim 中遍历跳转列表时离开当前缓冲区?
我经常在 Vim 会话中打开多个缓冲区。这意味着我的跳转列表存储来自多个缓冲区的位置。但是,经常当我使用 Ctrl+O 键盘快捷键跳转到上一个位置时,我不想离开缓冲区并想跳转到上一个位置“本地”到当前缓冲区。我该怎么做?
例如,假设我的跳转列表如下所示:
4 10 1 ~/aaa.m
3 20 1 ~/aaa.m
2 12 2 ~/xxx.m
1 15 1 ~/aaa.m
我想在第一次按 Ctrl+O< 时跳转到文件 aaa.m
的第 15 行/kbd>。重要的是,下次我按 Ctrl+O 时,我不想跳转到文件xxx.m
。相反,我想跳转到文件aaa.m
的第20行,即我在“当前”缓冲区中的先前位置。不过,默认的 Vim 行为是转到文件xxx.m
的第 12 行。
关于如何实现这一目标有什么想法吗?
I frequently have several buffers open in my Vim session. This means that my jump list stores locations from several buffers. However, frequently when I use the Ctrl+O keyboard shortcut to jump to a previous location, I do not want to leave the buffer and want to jump to previous locations “local” to the current buffer. How do I do this?
For example, assume my jump list looks as follows:
4 10 1 ~/aaa.m
3 20 1 ~/aaa.m
2 12 2 ~/xxx.m
1 15 1 ~/aaa.m
I want to jump to line 15 of file aaa.m
the first time I press Ctrl+O. Importantly, the next time I press Ctrl+O, I do not want to jump to file xxx.m
. Rather, I want to jump to line 20 of file aaa.m
, that is, my previous location within the “current” buffer. The default Vim behaviour, though, is to take me to to line 12 of file xxx.m
.
Any ideas on how I can achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试下面的跳转列表遍历函数。它一步一步地
从一个跳转列表位置到另一个位置(使用 Ctrl+O
或 Ctrl+I 取决于值
提供给其
back
和forw
参数),如果当前位置与其起始缓冲区位于同一缓冲区中。
如果无法找到属于
当前缓冲区,函数返回跳转列表中的位置
这是调用该函数之前的当前值。
将此函数用作
Ctrl+O/Ctrl+I - 替换
锁定到当前缓冲区,创建映射,如下所示。
Try the following jump-list traversing function. It steps successively
from one jump-list location to another (using Ctrl+O
or Ctrl+I depending on the values that are
supplied to its
back
andforw
arguments), and stops if the currentlocation is in the same buffer as that buffer it has started from.
If it is not possible to find a jump-list location that belongs to the
current buffer, the function returns to the position in the jump list
that was the current one before the function was called.
To use this function as a
Ctrl+O/Ctrl+I-replacement
locked to the current buffer, create mappings as it is shown below.
也许 EnhancedJumps 插件会有所帮助。
安装此插件后,仅当随后立即再次重复相同的跳转命令时,才会跳转到另一个缓冲区。
Maybe the EnhancedJumps plugin will help.
With this plugin installed, the jump to another buffer is only done if the same jump command is repeated once more immediately afterwards.