我该如何跳转到vim中不同选项卡中的标记? [英] How do I jump to markers within different tabs in vim?
问题描述
我正在使用MacVim,通常会打开许多选项卡.我希望能够在任何打开的文件中添加标记并在它们之间跳转. mK和K work great when the mark is in the same tab but I've got to use gt to find the tab and then
K来找到标记...必须有更好的方法吗?
I'm using MacVim and I usually have a number of tabs open. I'd like to be able to drop marks in any of my open files and jump between them. mK and K work great when the mark is in the same tab but I've got to use gt to find the tab and then
K to find the marker... there must be a better way?
推荐答案
这是一个快速且肮脏的黑客程序,可以满足您的需求.
Here is a quick and dirty hack that answers your need.
let s:marks = {}
function! s:Mark(name)
echomsg "new mark: " a:name
" todo: record the winnr/bufnr as well
let s:marks[a:name] = tabpagenr()
exe 'normal! m'.a:name
endfunction
function! s:Jump(how, name)
if has_key(s:marks, a:name)
let nr = s:marks[a:name]
tabfirst
let first = tabpagenr()
while tabpagenr() != nr
tabnext
if tabpagenr() == first
break
endif
endwhile
if tabpagenr() == nr
exe 'normal! '.a:how.a:name
" nominal termination
return
endif
endif
echoerr "tab-mark " . a:name . " not set"
endfunction
nnoremap m :call <sid>Mark(nr2char(getchar()))<cr>
nnoremap ` :call <sid>Jump('`', nr2char(getchar()))<cr>
nnoremap ' :call <sid>Jump("'", nr2char(getchar()))<cr>
问题:
-
通常,每个缓冲区的
-
标记都不同.在这里,所有标记都是全球性的.可能是,我们应该改为提供到
\m
,\'
,ang\*backtick*
marks are different for each buffer normally. Here, all the marks are global. May be, we should instead provide mappings to
\m
,\'
, ang\*backtick*
这不考虑拆分窗口.
这篇关于我该如何跳转到vim中不同选项卡中的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!