它往往不明確「正確」的比賽是什麼。目前,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插件看起來不錯,謝謝。 –