Vim 函数显示剩余 'Ctrl+I' 样式跳转的次数(并在状态行中显示输出)?
Vim function to display the number of remaining 'Ctrl+I' style jumps (and display output in the statusline)?
我经常使用 CTRL
+O
和 CTRL
+I
来遍历跳转列表。有时候我
发现我忘记了我是否在跳转列表的末尾,然后我按
CTRL
+I
期望在跳转列表中前进,但我却无处可去,
再次击中,无处可去,然后才得出结论,我已经到了尽头
跳转列表。我觉得这在精神上很刺耳,想编码
我的状态行中的信息。所以我要找的是一个函数来告诉我
两件事之一:
如果我还没有到达跳转列表的末尾,就像第一个一样
下面的示例,我想要与最后一行关联的跳转编号(在那
例如 '1')
如果我在跳转列表的末尾,如第二个示例
下面,我要return归零。
示例 1:我在撰写此问题时的跳转列表并且我跳转了
返回 CTRL
+O
:
jump line col file/text
2 1 0 This is a small thing but it irritates me...
> 0 4 37 find that I forget whether I'm at the end of the jumplist and I press
1 5 78 `CTRL`+`I` expecting to go forwards in the jumplist, and instead I go nowhere,
示例 2:当我一直点击 CTRL
+I
直到我走到尽头时的样子
跳转列表:
jump line col file/text
3 1 0 This is a small thing but it irritates me...
2 4 37 find that I forget whether I'm at the end of the jumplist and I press
1 5 78 `CTRL`+`I` expecting to go forwards in the jumplist, and instead I go nowhere,
>
非常感谢!
我想你可以使用 getjumplist()
。它returns一个列表,第一项是跳转列表,第二项是最近使用的跳转位置。 (参见:help getjumplist()
。)所以你可以比较它的第一项和第二项的长度。您可以在 vimrc.
中放置如下函数
function! RemainingJumps()
let [l:jumplist, l:pos] = getjumplist()
return max([0, len(l:jumplist) - l:pos - 1])
endfunction
至于在状态栏中打印其结果,我想这取决于您如何配置您的状态栏:您是使用 lightline.vim、vim-airline 还是香草状态栏。
哦,我发现你的 vimrc 在没有插件的情况下从头开始构建状态行!在这种情况下,您可以添加类似
的内容
set statusline+=\ %{RemainingJumps().'\ Jumps'}
我经常使用 CTRL
+O
和 CTRL
+I
来遍历跳转列表。有时候我
发现我忘记了我是否在跳转列表的末尾,然后我按
CTRL
+I
期望在跳转列表中前进,但我却无处可去,
再次击中,无处可去,然后才得出结论,我已经到了尽头
跳转列表。我觉得这在精神上很刺耳,想编码
我的状态行中的信息。所以我要找的是一个函数来告诉我
两件事之一:
如果我还没有到达跳转列表的末尾,就像第一个一样 下面的示例,我想要与最后一行关联的跳转编号(在那 例如 '1')
如果我在跳转列表的末尾,如第二个示例 下面,我要return归零。
示例 1:我在撰写此问题时的跳转列表并且我跳转了
返回 CTRL
+O
:
jump line col file/text
2 1 0 This is a small thing but it irritates me...
> 0 4 37 find that I forget whether I'm at the end of the jumplist and I press
1 5 78 `CTRL`+`I` expecting to go forwards in the jumplist, and instead I go nowhere,
示例 2:当我一直点击 CTRL
+I
直到我走到尽头时的样子
跳转列表:
jump line col file/text
3 1 0 This is a small thing but it irritates me...
2 4 37 find that I forget whether I'm at the end of the jumplist and I press
1 5 78 `CTRL`+`I` expecting to go forwards in the jumplist, and instead I go nowhere,
>
非常感谢!
我想你可以使用 getjumplist()
。它returns一个列表,第一项是跳转列表,第二项是最近使用的跳转位置。 (参见:help getjumplist()
。)所以你可以比较它的第一项和第二项的长度。您可以在 vimrc.
function! RemainingJumps()
let [l:jumplist, l:pos] = getjumplist()
return max([0, len(l:jumplist) - l:pos - 1])
endfunction
至于在状态栏中打印其结果,我想这取决于您如何配置您的状态栏:您是使用 lightline.vim、vim-airline 还是香草状态栏。
哦,我发现你的 vimrc 在没有插件的情况下从头开始构建状态行!在这种情况下,您可以添加类似
的内容set statusline+=\ %{RemainingJumps().'\ Jumps'}