tags:

views:

39

answers:

2

I found that when multiple tags exist for a given symbol, Vim can't select the right tag . I don't know whether it's always the truth , but at least I met this problem for several times.

To put my problem more clear, let's say there are two classes : class A and class B in two different cpp files. Both of them defined a public member function called AddContext. Then somewhere else in the source code of the project , let's denote it as place x, a instance of A called its memeber function AddContext.

You generate tags for the the project and go to place x and move the cursor under "AddContext" , and finally hit ctr-] .To your dismay, vim jump to the definition of B::AddContext rather than A::AddContext.

So is there any good vim practice to solve the problem as I momentioned ?

+2  A: 

Use

:tnext
:tprevious

or

:tn
:tp

This will help to solve your problem in the manual way. Ctags and Vim do not understand the context. So you have to determine it yourself.

Mapping those commands is a good way to deal with the problem.

You also can try 0scan plugin. It can help to choose desired place to jump in a more convenient way. Put your cursor on a symbol and press 0u.

Mykola Golubyev
A: 

Instead of just pressing ^] use g^]. This will show a menu if there are multiple tags for the identifier under the cursor so you can pick the tag you want to jump to. If you jump to a tag and it's not the right one, you can use the :tselect (you can abbreviate to :ts) to bring up the menu for the last tag you followed.

Geoff Reedy