Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim 正在寻找一种正确排序ctags匹配项的方法_Vim - Fatal编程技术网

Vim 正在寻找一种正确排序ctags匹配项的方法

Vim 正在寻找一种正确排序ctags匹配项的方法,vim,Vim,我有一个正确配置了ctags的代码库。当我这样做时,:tjump keyword会显示关键字的潜在匹配列表 但是,这些匹配项的顺序不正确。我正在寻找一种方法来正确排列匹配项,以便最佳匹配项位于列表的顶部。ie:-当我直接使用Ctrl-]时,第一次跳转应该到正确的位置 对于使用gf的GetFile导航,我找到了includeexpr,它允许我运行自定义逻辑来确定要跳转到的文件 Vim是否具有更改标记结果的类似功能 我正在考虑的另一种方法是从:tjump中获取标记列表,进行排序,并覆盖Ctrl-]的

我有一个正确配置了
ctags
的代码库。当我这样做时,
:tjump keyword
会显示
关键字
的潜在匹配列表

但是,这些匹配项的顺序不正确。我正在寻找一种方法来正确排列匹配项,以便最佳匹配项位于列表的顶部。ie:-当我直接使用
Ctrl-]
时,第一次跳转应该到正确的位置

对于使用
gf
的GetFile导航,我找到了
includeexpr
,它允许我运行自定义逻辑来确定要跳转到的文件

Vim是否具有更改
标记
结果的类似功能

我正在考虑的另一种方法是从
:tjump
中获取标记列表,进行排序,并覆盖
Ctrl-]
的映射

对于这种方法,是否有从
:tjump
获取匹配列表的函数

任何其他的想法,以确保正确的比赛是在顶部也欢迎


谢谢。

通常不清楚什么是“正确”匹配。目前,Vim使用以下逻辑(来自
:help tag priority
):

如果您想实现自己的自定义逻辑,那么(据我所知)没有任何类似于
includeexpr
的方法可以帮助您

您可以创建多个标记并在
tags
设置中对它们进行排序,以便对您的首选项进行编码。然而,很难说那会是什么,而且很可能需要一些实验

另一个更复杂的操作是覆盖
键(或者其他键,比如
]
),以执行不同的操作。比如:

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
nnoremap:calljumptotag()
功能!s:JumpToTag()
“尝试在光标下查找一个单词
让当前单词=展开(“”)
“看看有没有
如果当前单词=“”
echomsg“光标下无单词”
返回
恩迪夫
“查找给定单词的所有标记
let tags=taglist(“^.”当前单词“$”)
“如果找不到标签,就跳出去
如果为空(标签)
echomsg“未找到:”.当前单词的标记
返回
恩迪夫
“使用第一个标记,或者在这里实现一些更复杂的逻辑
让所选标签=标签[0]
“编辑相关文件,跳转到标记的位置
exe“编辑”。已选择\u tag.filename
exe已选择_tag.cmd
端功能
您可以使用
taglist()
函数定位光标下单词的标记。然后,您可以实现自己的逻辑,比如过滤掉测试文件,或者按照特定标准进行排序,而不是
let selected_tag=tags[0]


不幸的是,由于您正在手动编辑文件,因此无法维护先前的
:tnext
:t命令。您可以将其替换为快速修复或位置列表,使用带有标记的
setqflist()
函数按您喜欢的方式排序,然后使用
:cnext
:cprev
导航。但这需要更多的脚本:)。如果你决定进入这个兔子洞,你可能想看看我的插件的来源以获得灵感。

根据你对@AndrewRadev的回答的评论:

我经常创建一个“mktags”脚本来构建ctag,然后从标记文件中筛选出我想要忽略的标记。例如(对于sh、ksh、bash、zsh):


这是一个超级答案!非常感谢。我将使用
标记列表
。我只有几个
interface
def是需要过滤掉的误报。Tagfinder插件看起来也很棒,谢谢。
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
ctags "$@"
egrep -v "RE-for-tags-to-delete" tags > tags.$$
mv tags.$$ tags