Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding definitions/references to C++ class members in Vim

Tags:

c++

vim

I'm using Vim for a C++ project that I've started working on and I've been spending a lot of time lately browsing through the existing code to get a hang of it. To make the browsing easier, I've setup ctags and cscope in Vim to jump to definitions and find references.

However, I find that neither of them are intelligent enough to know which class a member variable/function belongs to. For example:

class Square;
...

Square a;
...
a.rotate();

Attempting to find the definition of rotate() will bring up member functions from other classes too, like Triangle. I use g] in Vim to bring up a list of matching tags and fortunately ctags lists the associated class for each entry. However, when there are 200 classes with the same member function, it can be tiresome to hunt down the correct tag.

Also, if I am at a function definition:

Square::rotate()
{
    ...
}

Attempting to find all calls to rotate() using cscope brings up calls to Triangle's and other classes' rotate functions.

Because of this, I find myself jumping to Visual Slickedit every now and then to find the definition or reference to a member function or member variable. Is there any way I can accomplish this in good old Vim?

like image 423
tj511 Avatar asked Dec 02 '09 05:12

tj511


3 Answers

SrcExpl might be the plugin you needed. Try it.

like image 81
xis Avatar answered Sep 28 '22 18:09

xis


I've looked for better solutions than cscope in the past, but never found something. In the end perhaps cscope lack of intelligence isn't really that much of a bother.

The problem is that there is no powerful and open intellisense library on the market. Perhaps CodeInsight.

like image 23
StackedCrooked Avatar answered Sep 28 '22 17:09

StackedCrooked


Seems like this would be a good candidate http://vim.wikia.com/wiki/C%2B%2B_code_completion. I had some good luck with it doing similar things in Java. Not entirely sure it gets you everything you're trying to do though.

like image 26
jho Avatar answered Sep 28 '22 18:09

jho