我正在尝试将 vim 与 ctags 和/或 cscope 一起使用,它工作得很好,但我遇到了一些问题,其中 ctags 跳转到了错误的符号。例如在下面的代码中,如果我将光标放在 main() 中的符号“a”上并按 Ctrl+] 转到定义,我将被引导到我的“虚拟结构”中的“char a”,但我想被定向到 main 中的“int a”。 ctags 或 cscope 可以处理这个问题还是符号需要唯一的名称?
struct dummy
{
char a;
};
int main ()
{
int a = 1;
a = a + 2;
return a;
}
最佳答案
是的,ctags 通过将所有备选方案放入标签文件来处理这个问题;你可以打开tags
文件来验证这一点。
您的问题是由 <C-]>
的行为引起的命令;来自 :help CTRL-]
:
When there are several matching tags for {ident}, jump to the [count] one. When no [count] is given the first one is jumped to. See |tag-matchlist| for jumping to other matching tags.
您可以提供 [count]
在命令之前(通过 <C-t>
跳转错误标签后先跳回到原来的位置),或者使用 :tselect
命令代替,它列出了所有标记选项和查询要跳转到的标记。
关于ctags 可以区分具有相同名称的不同符号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24955347/