如何设置vim地图不改变跳转列表?

发布于 2025-01-20 01:46:11 字数 675 浏览 3 评论 0原文

[first line]

int test() {
    a   
    b
    c
    d
    {
        e
        f   
        g   
    }
}
  1. 当前与f一致的光标。
  2. 如果我按[[>,光标将转到[第一行]
  3. 我想要光标goto int test(){。因此,我设置了一个映射:nnoremap [[] [%
  4. 地图命令效果很好,有一个问题:如果我按ctrl+o,光标将转到最后一行}
  5. 我想要的是光标可以使用f返回到线路。

我尝试了nnoremap [[:keepjump normal] [%< cr>,但它不起作用。

我该如何实施?

  1. [[int test(){制作光标goto line。
  2. ctrl+o使光标跳回去。

我的VIM版本是VI改进的7.4

[first line]

int test() {
    a   
    b
    c
    d
    {
        e
        f   
        g   
    }
}
  1. The cursor in currently in line with f.
  2. If I press [[, the cursor will go to [first line].
  3. I want cursor goto int test() {. So I set a mapping: nnoremap [[ ][%.
  4. The map command works good, with one problem: if I press CTRL+O, cursor will go to the last line }.
  5. What I want is the cursor to go back to the line with f.

I tried nnoremap [[ :keepjumps normal ][%<CR>, but it does not work.

How can I implement this?

  1. press [[ make cursor goto line with int test(){.
  2. press CTRL+O make cursor jump back.

My vim version is Vi IMproved 7.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2025-01-27 01:46:11

跳跃列表的工作方式经常被误解。跳跃存储在跳跃列表中,仅记录了您制作的“跳跃”的 Origin 而不是其目的地。这意味着:help:keepjumps应该用于防止将新的 Origin 添加到跳跃列表中。

为了&lt; co&gt;跳回原点f,该来源必须存在于跳跃列表中>必须遗漏。

做:

nnoremap [[ :keepjumps normal ][%<CR>

您有效地阻止了 arourt f orient }要添加到跳跃列表 中。

您可以通过移动] [中移动:keepjumps 命令:

nnoremap [[ ][:keepjumps normal %<CR>

The way the jump list works is very often misunderstood. A jump, as stored in the jump list, only records the origin of the "jump" you made, not its destination. This means that :help :keepjumps is supposed to be used to prevent a new origin to be added to the jump list.

In order for <C-o> to jump back to the origin f, that origin must be present in the jump list so it's only the origin } that must be left out.

In doing:

nnoremap [[ :keepjumps normal ][%<CR>

you are effectively preventing both the origin f and the origin } to be added to the jump list.

You can fix your mapping by moving ][ out of the :keepjumps command:

nnoremap [[ ][:keepjumps normal %<CR>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文