In VS Code, there's a nice utility where I can right-click a keyword and it will allow me to view where that variable/function/macro/etc. is declared, defined, or used. For example, let's say in the following code:
I want to goto
the place in the file (stdio.h
) that declares this function. Is there a simple way where I can 'follow a file/function' in vim to be able to view this information upstream?
For reference, I do have ctags
installed and my stdlib
is located at:
$ gcc --print-file-name=libc.a
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a
Yes, use the tag operation. If you have generated a tags
file of the set of files you are interested in. The ctags
command can generate it for C and C++.
Then, in the source code, position vim's cursor on the symbol to look up and press ctrl-]
character.
===== addendum =====
$ 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