Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

c - Vim finding where functions and such are declared

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:

Code in Vim

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
question from:https://stackoverflow.com/questions/65879526/vim-finding-where-functions-and-such-are-declared

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...