Vim 查找声明函数等的位置

Vim finding where functions and such are declared

在 VS Code 中,有一个很好的实用程序,我可以在其中右键单击一个关键字,它可以让我查看那个 variable/function/macro/etc 的位置。被声明、定义或使用。例如,让我们在下面的代码中说:

我想 goto 文件 (stdio.h) 中声明此函数的位置。有没有一种简单的方法可以让我在 vim 中 'follow a file/function' 能够在上游查看此信息?

作为参考,我确实安装了 ctags,我的 stdlib 位于:

$ gcc --print-file-name=libc.a 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a

是的,使用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

要仅搜索包含的文件,请使用 [i[d:h include-search 中的其他命令。无需为此工作生成标签。唯一的要求是您的 :h 'path' 设置正确。