Vim 查找函数等的声明位置

问题描述 投票:0回答:3

在 VS Code 中,有一个很好的实用程序,我可以右键单击关键字,它允许我查看该变量/函数/宏/等的位置。被声明、定义或使用。例如,在下面的代码中:

我想要

goto
文件中声明此函数的位置 (
stdio.h
)。有没有一种简单的方法可以让我在 vim 中“跟踪文件/函数”以便能够在上游查看此信息?

仅供参考,我确实安装了

ctags
并且我的
stdlib
位于:

$ gcc --print-file-name=libc.a 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a
c vim
3个回答
3
投票

是的,使用tag操作。如果您已经生成了您感兴趣的文件集的

tags
文件。
ctags
命令可以为 C 和 C++ 生成它。

然后,在源代码中,将 vim 的光标定位到要查找的符号上,然后按 ctrl-

]
字符。

======附录====

$ gcc -M > dir_list    # list directories which are searched    
$ vim dir_list      # edit file list to remove \ at end of line
                    # and remove the `.o` file listed
$ ctags -L dir_list *.c   # examine source files for symbols

1
投票

要仅搜索包含的文件,请使用

[i
[d
以及
:h include-search
中的其他命令。无需生成标签即可实现此功能。唯一的要求是您的
:h 'path'
设置正确。


0
投票

如果您想找到该函数在项目外部的声明位置。可能对你有帮助,请查看以下答案。

跳转至函数定义

© www.soinside.com 2019 - 2024. All rights reserved.