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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With