Alex B
Alex B

Reputation: 84832

vim, ctags, and identically named identifiers

vim + ctags works well for C projects, since C does not allow function overloading and, in general encourages manual prefixing of symbols due to rudimentary scoping facilities.

In C++, functions are frequently overloaded, and overridden in subclasses. This makes vim always jump to the tag in the wrong class on "Ctrl + ]". Is there a way to make it behave a little more intelligently? I know I can bring a list with tag alternatives, but that's insanely annoying to always have to bring up this list, and find a needed tag by number whenever I want to jump to definition.

Upvotes: 18

Views: 3242

Answers (4)

gpojd
gpojd

Reputation: 23065

I use tjump a lot. It supports tab completion which is helpful. If multiple tags are found, it will give a list for you to select from, if only one is found, it will jump right to the tag (unlike tselect).

Usage:

:tj foo

Upvotes: 8

Mykola Golubyev
Mykola Golubyev

Reputation: 59844

You can use my script which will help you to select tag you need by typing some letters of the class name or special tags like 'field', 'function', 'constructor', etc.

http://www.vim.org/scripts/script.php?script_id=2507

Upvotes: 5

bayda
bayda

Reputation: 13581

I know two workarounds for your porblem ( it seems you knew it too ):

  • Use :tselect and tag name or g] with cursor on tag for get list of matched tags and goto on tag by number from list;
  • map :tnext or :tprev on hotkeys ( I've mapped on F6 and F7 ) and find needed function manualy;

Upvotes: 7

Loki Astari
Loki Astari

Reputation: 264471

There is also "tagNext" to move to the next tag (or :tn<enter>)

Upvotes: 13

Related Questions