First things first: Vim has never been, is not and will probably never be a proper alternative to an IDE. Whoever made you believe that should be shot and you should be shot too for believing such nonsense.
I'm only half-joking.
Vim is a very powerful programming-oriented text editor but the simple fact that you need to run a dumb external code indexer to get a dumb "jump to definition" or another code indexer to get another dumb "jump to usage" should be a hint that Vim can't realistically be compared to an IDE. Hint: the I
in IDE means "Integrated" and the E
means "Environment". Since you can't get proper integration and would be hard-pressed to consider Vim as an environment, there's no IDE, here. Only a text editor with many plugins doing different things in different ways and, above all, no serious way to understand your code which is the #1 feature of a descent IDE.
Many users/bloggers claim they are using "Vim as an IDE" or that you could, too, turn Vim into a Python or whatever IDE but the truth is that Vim lacks all the low-level features that would make such a thing possible. You can turn it into something that looks like an IDE, if you are somehow able to believe in your own lies, but it will probably never be an IDE.
Whatever…
The default behavior (which can't be altered in your configuration) of
<C-]>
or:tag foo
is to jump to the first hit in yourtags
file(s). Neither Vim nor Ctags know about scope. At best, you can be treated with a list from which to choose the correct tag (:ts foo
org]
) but that's how far you can go.Depending on the languages you work with, Cscope might be better at indexing your code but the general principle is the same as with Ctags. Cscope offers a "jump to usage" feature so it might be worth switching just for it.
Making sure the correct
tags
file(s) are used can be a pain and the doc is surprisingly not very helpful in that regard. There are a bunch of plugins designed to make it simpler that you could try, EasyTags comes to mind.I admit I don't work on very large projects and not even in C so maybe this won't seem useful but this line in my
~/.vimrc
makes working withtags
easier:set tags=./tags;/,tags;/
With this setting, Vim looks up and up (non-recursively) until
/
fortags
files. The main point of this is to have a singletags
file at the root of each of my projects that can be used from every file in that project without ever needing to tell Vim where to look for atags
file.One way to deal with your Java/C mixups could be to put your projects into language-specific directories:
C/ c.tags proj1/ tags … proj2/ tags … Java/ j.tags proj3/ tags … proj4/ tags …
and put you "global" tags
files at their root as well as project-specific tags
files at the root of their respective projects.
Another way to deal with that issue could be to instruct Vim to load specific tags
files depending on the filetype:
autocmd FileType c setlocal tags=/path/to/your/global/c/tags,./tags;/,tags;/