Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ctags in vim to go to definition, not declaration

Tags:

vim

ctags

I'm having the problem that ctags in vim/gvim takes me to a forward declaration a lot of times instead of to the actual definition of the function.

Any way to get around that?

like image 301
Robert S. Barnes Avatar asked Jun 28 '09 10:06

Robert S. Barnes


People also ask

Where are ctags stored?

Ctags is a tool that will sift through your code, indexing methods, classes, variables, and other identifiers, storing the index in a tags file.

How do I set tags in Vim?

Select tag from tag list. You can select a particular tag from the tag list after opening the file in the vim editor by using ctags command. Open any source code in vim editor and type ':tselect' to find out the list of tag list of current source code. Here, the same file, abs_num.py is used to check this command.


2 Answers

I think that the easiest way is to use "g ctrl-]" instead of just "ctrl-]". If there is only one match, it will take you there. If there are multiple matches, it will list them all, letting you choose the one you want, just like :tselect. The best of both worlds. :)

like image 60
Derek Avatar answered Oct 24 '22 08:10

Derek


You should be able to use tn and tp to jump to the various matching tags.

  • Press ^] to take you to the first match.
  • If that's not the match you want, type :tn to go to the next.
  • If you typed :tn too many times you can type :tp to return to the previous one.
like image 10
Nathan Fellman Avatar answered Oct 24 '22 09:10

Nathan Fellman