As is displayed here: http://andrewradev.com/2011/06/08/vim-and-ctags/

We can setup ctags to allow us to enter functions and modules as they are being called. But the problem is that I want to enter a the function the given instance is a member of. So say,

ibase=new mbase({});

Then if I'm over the onload function, and hit ctrl-] to enter the function, I want to enter the onload function that is a member of the module mbase.

Currently it just enters whatever onload function it encountered first. Which is not what I need.

How do I make the goto functionality take into account which module the instance is a member of?

1 Answer 1


EDIT: Sorry I misread your question.

Either you use a plugin that permits you to select an overload among others. That's one of the reasons I wrote lh-tags. In all cases, you'll need to know by yourself what is the type of your variable. This is not perfect, but more than enough for me. You still have :pselect, but I've always found it clumsy.

You could also rely on more clever tools. I'm thinking about http://langserver.org/ . I wonder whether it wouldn't be a better solution. The advantage of LangServer is we can expect it to be able to rely on a tool specialized for the languages we work with.

If you want to stick to a pure ctags solution, first prefer universal-ctags. Then, if you want to automatically select the right function, you'll have to write some non trivial code.

  1. First, you'll need to extract the type of the variable. You can start with the gd command to goto to the variable definition. If it fails, you could run (universal-!)ctags on the current file and make sure to ask for variable declarations/definitions.
  2. With this new info, you should be able to find the line where the variable is defined. (*)
  3. There, you'll have to analyse the line found to extract the type: mbase -- in other languages we have other kind of declarations.
  4. Eventually you can filter(taglist(funcname), 'v:val.class == "mbase"'), and jump by yourself to this entry (there is everything needed to behave as a tag jump in lh-tags) -- the exact dictionary key to analyse may depend on the language.

Be aware that if your language permits stuff like

myvar = new SomeType1();
if (...)
   myvar = new SomeOtherType2();

or even

myvar = new SomeType1();
myvar = new SomeOtherType2();

or worse

myvar = f(g());

Good luck with ctags in order to extract the exact type. We have other problems when the language supports overriding.

(*) NB: In lh-cpp, I have a series of functions (that I'll like to refactor) I use to extract the type of a C++ variable. It be may adapted to your language. In lh-dev I have an undocumented API to run ctags on the fly on the current file to extract some specific information without modifying the current tag database -- that I'm also likely to refactor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.