Reputation: 75
I tried to use ctags with vim and I discovered the following problem:
First, let's see the following picture:
If I press C-] then the cursor will move on line 7 as you can see here:
But if I type the command :tn the cursor is still on line 7 instead of line 14, where the next tag is. Why is this happening and how can I solve this? If you look at the following picture on the bottom left it shows: "tag 2 of 3" so that means :tn works, I think, but the cursor doesn't move.
Upvotes: 1
Views: 362
Reputation: 196596
If you look at your tags
file you can see that your three definitions for fc()
are identical:
fc pam.cpp /^ void fc() {$/;" f class:A
fc pam.cpp /^ void fc() {$/;" f class:B
fc pam.cpp /^ void fc() {$/;" f class:C
By default, Ctags doesn't provide a line:column information to Vim, it merely provides a search pattern. Since it's the same search pattern for all three tags, Vim always performs the same search and always ends up at the same spot. It doesn't matter if you use :tag fc
, <C-]>
, :tnext
, :tselect
or any of their friends.
With the -n
option, Ctags outputs line numbers instead of search patterns:
fc pam.cpp 14;" f class:B
fc pam.cpp 21;" f class:C
fc pam.cpp 7;" f class:A
That's better because Vim can now jump to the correct line but the tags are ordered incorrectly. One way to fix this would be to use the -u
option:
A pam.cpp 5;" c file:
fc pam.cpp 7;" f class:A
B pam.cpp 12;" c file:
fc pam.cpp 14;" f class:B
C pam.cpp 19;" c file:
fc pam.cpp 21;" f class:C
In conclusion, you should generate your tags
with the -n
and -u
options. Something like:
$ ctags -Rnu .
See $ man ctags
.
Upvotes: 3