问题
Say I have N class' defined as:
1 class Bar0
2 {
3 public:
4 void func();
5 };
6
7 void Bar0::func()
8 {}
9
10 class Bar1
11 {
12 public:
13 void func()
14 };
15
16 void Bar1::func()
17 {}
Say I am using ctags, my tags file is sorted and I am using it with vim. When I place my cursor over func
on line 13 and hit Ctrl+]. This will/could take me to the definition of Bar0
's member function func
on line 7 because its lexicographical ordering comes before Bar1
's. To get around that I could use g+] and this would open a separate buffer where I could search for the one I want. However, lets say func
is a virtual member function that is in about 20 classes. At that point I could also use Ctrl+] with :tp
and :tn
to shuffle through all 20. Thus, my question. Is there a plugin or code I can add to my .vimrc, such that I can use it in conjunction with ctags to resolve member functions based on the scope of its class faster than a linear search through all possible options? I would like to stay away from plugins like OmniCppComplete.
回答1:
In lh-tags, I wrap ctags results in order to display them, search among them (with /
), filter them, etc.
Unfortunately, I only use ctags which doesn't understand C++: it won't be able to know which overload a call site is referring to.
That's where vim-clang and clang-indexer came into the equation. I haven't spent time in them in ages. I'm not even sure clang-indexer still compiles with the latest version of clang. The idea is to built a code database, and to extract the real context from the current code in order to correctly identify overloads and so on. The last time I used, it had troubles sometimes to identify the current context.
Note that YouCompleteMe should be able to jump to a function declaration, and in the best case scenario to a function definition, that is in the same translation unit as the current file.
来源:https://stackoverflow.com/questions/35729698/vim-plugin-to-resolve-a-member-function-more-efficiently-using-ctags