它往往不明确“正确”的比赛是什么。目前,Vim使用下面的逻辑(从:help tag-priority
):
When there are multiple matches for a tag, this priority is used:
1. "FSC" A full matching static tag for the current file.
2. "F C" A full matching global tag for the current file.
3. "F " A full matching global tag for another file.
4. "FS " A full matching static tag for another file.
5. " SC" An ignore-case matching static tag for the current file.
6. " C" An ignore-case matching global tag for the current file.
7. " " An ignore-case matching global tag for another file.
8. " S " An ignore-case matching static tag for another file.
如果你想实现自己的定制逻辑,没有什么(我知道的)类似includeexpr
,可以帮助你。
您可以创建多个标签,并在编码您喜欢这样的方式,责令其在tags
设置。尽管这很难说,但很可能需要一些试验。
你可以做的另一个更复杂的事情是覆盖<c-]>
密钥(也可能是其他人,比如<c-w>]
)来做一些不同的事情。喜欢的东西:
nnoremap <c-]> :call <SID>JumpToTag()<cr>
function! s:JumpToTag()
" try to find a word under the cursor
let current_word = expand("<cword>")
" check if there is one
if current_word == ''
echomsg "No word under the cursor"
return
endif
" find all tags for the given word
let tags = taglist('^'.current_word.'$')
" if no tags are found, bail out
if empty(tags)
echomsg "No tags found for: ".current_word
return
endif
" take the first tag, or implement some more complicated logic here
let selected_tag = tags[0]
" edit the relevant file, jump to the tag's position
exe 'edit '.selected_tag.filename
exe selected_tag.cmd
endfunction
可以使用taglist()
功能定位标签光标下的单词。然后,而不是let selected_tag = tags[0]
,您可以实现自己的逻辑,如筛选出测试文件或按特定条件排序。
不幸的是,由于您正在手动编辑文件,因此这不会保留:tnext
和:tprevious
命令。您可以用quickfix或位置列表替换它,使用setqflist()
函数,并按照您喜欢的方式对标签进行排序,然后使用:cnext
和进行导航。但是这是一个更多的脚本:)。如果你决定放下这个兔子洞,你可能想看看我的tagfinder插件的来源,以获取灵感。
这是一个超级回答!谢谢!我要用'taglist'去。我只有几个'interface' defs是需要过滤掉的误报。 Tagfinder插件看起来不错,谢谢。 –