Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim, ctags, and identically named identifiers

Tags:

c++

vim

ctags

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.

like image 582
Alex B Avatar asked Mar 18 '09 01:03

Alex B


4 Answers

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

like image 172
Martin York Avatar answered Nov 01 '22 11:11

Martin York


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
like image 27
gpojd Avatar answered Nov 01 '22 11:11

gpojd


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;
like image 7
bayda Avatar answered Nov 01 '22 12:11

bayda


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

like image 5
Mykola Golubyev Avatar answered Nov 01 '22 12:11

Mykola Golubyev