简体   繁体   中英

How to have Vim recognize the object type when accessing an STL container, for autocompletion

I have the omnicppcomplete plugin with exuberant ctags, I generate tags for projects with the following command:

ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .

What I am trying to achieve is to have Vim recognize the type of an object when I access it through an STL container, to provide me with an appropriate list of autocomplete suggestions.

For example suppose the IntWrapper object has a getTheInt() method and I have a vector of IntWrappers :

std::vector<IntWrapper> wrappers;

If I have the following code:

for (size_t i = 0; i < wrappers.size(); i++) {
    wrappers[i].<VIM Cursor is here>
}

I'd like VIM to understand that wrapper[i] is of type IntWrapper and to give me the getTheInt() method as the first autocompletion choice, along with documentation, as if I operated on an IntWrappers object directly.

To make clear what I would expect, the first screenshot below is what happens when I ask for autocompletion on the vector, the second one is what happens when I access the object directly, and what I'd like to achieve even with stl containers.

表达未找到

(The sentence highlighted in red above says expression not found )

工作

Is there any plugin (I don't care about CPU expensiveness) to do this?

Many thanks.

Actually, I think that omnicomplete can't deal with context issue, so you can't use it for your purpose. A way to do C++/STL auto-completion is to use clang_complete (or here ).

The performance seems to be quite problematic though (Have a look here : How to improve the completion speed of clang_complete? ).

A nice tutorial on the subject (configure vim + clang for C++ STL completion) could be found here : http://zwiener.org/vimautocomplete.html

Ref:

NB : Another option is to use gccsense which is a stand alone tool using GCC's code analyzers. Here is the link to the project homepage : http://cx4a.org/software/gccsense/ and on two SO questions about its use :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM