Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: How to jump to definition in external C header file

Tags:

vim

I'm browsing some C code. I ran into a variable that is defined in a header file. How can i move my cursor under this variable and jump to see its definition ?

Thanks

like image 838
McBear Holden Avatar asked Aug 27 '11 11:08

McBear Holden


1 Answers

Achieving this in vim can be done by using a tag file.

You can generate a tag file with the ctags or exhuberant-ctags program.

cd in the directory of your project and run:

ctags -R

This will generate a file named tags that contain a list of all symbols in your source code, with their location.

Vim knows how to use these files to get you to the correct location. When your cursor is over a symbol, just hit CTRL-] to get to its definition. And you can return where you were by hitting CTRL-T.

See :help tags, :help CTRL-] and :help CTRL-T

Vim can use multiple tag files at the same time. For example you could have one for your project and one for each library you use. For this, just generate the various tag files and add them in the tags setting:

set tags=./tags,./TAGS,tags,TAGS,/mytags/library1,/mytags/library2

./tags,./TAGS,tags,TAGS is the default value for tags; it searches for tags or TAGS in the current directory and in the directory of the current file.

like image 169
Arnaud Le Blanc Avatar answered Oct 22 '22 20:10

Arnaud Le Blanc