简体   繁体   English

如何让Vim在访问STL容器时识别对象类型,以实现自动完成

[英]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: 我有omnicppcomplete插件和繁琐的ctags,我使用以下命令为项目生成标签:

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. 我想要实现的是让Vim在通过STL容器访问它时识别对象的类型,为我提供适当的自动完成建议列表。

For example suppose the IntWrapper object has a getTheInt() method and I have a vector of IntWrappers : 例如,假设IntWrapper对象有一个getTheInt()方法,我有一个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. 我希望VIM理解wrapper [i]是IntWrapper类型并且给我getTheInt()方法作为第一个自动完成选项,以及文档,就像我直接在IntWrappers对象上操作一样。

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. 为了弄清楚我的期望,下面的第一个截图是当我要求对向量自动完成时会发生什么,第二个是当我直接访问对象时会发生什么,以及即使使用stl容器我也想要实现的。

表达未找到

(The sentence highlighted in red above says expression not found ) (上面用红色突出显示的句子表示未找到表达式

工作

Is there any plugin (I don't care about CPU expensiveness) to do this? 有没有插件(我不关心CPU昂贵)这样做?

Many thanks. 非常感谢。

Actually, I think that omnicomplete can't deal with context issue, so you can't use it for your purpose. 实际上,我认为omnicomplete无法处理上下文问题,因此您无法将其用于您的目的。 A way to do C++/STL auto-completion is to use clang_complete (or here ). 一种做C ++ / STL自动完成的方法是使用clang_complete (或这里 )。

The performance seems to be quite problematic though (Have a look here : How to improve the completion speed of clang_complete? ). 虽然性能似乎很成问题(请看这里: 如何提高clang_complete的完成速度? )。

A nice tutorial on the subject (configure vim + clang for C++ STL completion) could be found here : http://zwiener.org/vimautocomplete.html 关于这个主题的一个很好的教程(为C ++ STL完成配置vim + clang)可以在这里找到:http: //zwiener.org/vimautocomplete.html

Ref: 参考:

NB : Another option is to use gccsense which is a stand alone tool using GCC's code analyzers. 注意:另一个选择是使用gccsense,这是一个使用GCC代码分析器的独立工具。 Here is the link to the project homepage : http://cx4a.org/software/gccsense/ and on two SO questions about its use : 以下是项目主页的链接: http//cx4a.org/software/gccsense/以及关于其使用的两个SO问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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