C++ Vim 中的自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1115876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Autocompletion in Vim
提问by Konrad Rudolph
In a nutshell, I'm searching for a workingautocompletion feature for the Vim editor. I've argued beforethat Vim completely replaces an IDE under Linux and while that's certainly true, it lacks one important feature: autocompletion.
简而言之,我正在为 Vim 编辑器寻找有效的自动完成功能。我之前曾说过Vim 完全取代了 Linux 下的 IDE,虽然这确实是事实,但它缺少一个重要功能:自动完成。
I know about Ctrl+N, Exuberant Ctags integration, Taglist, cppcompleteand OmniCppComplete. Alas, none of these fits my description of “working autocompletion:”
我知道Ctrl+ N、Exuberant Ctags 集成、Taglist、cppcomplete和OmniCppComplete。唉,这些都不符合我对“工作自动完成”的描述:
- Ctrl+Nworks nicely (only) if you've forgotton how to spell
class
, orwhile
. Oh well. - Ctagsgives you the rudiments but has a lot of drawbacks.
- Taglistis just a Ctags wrapper and as such, inherits most of its drawbacks (although it works well for listingdeclarations).
- cppcompletesimply doesn't work as promised, and I can't figure out what I did wrong, or if it's “working” correctly and the limitations are by design.
- OmniCppCompleteseems to have the same problems as cppcomplete, i.e. auto-completion doesn't work properly. Additionally, the
tags
file once again needs to be updated manually.
- Ctrl+N如果您忘记了如何拼写
class
, 或while
. 那好吧。 - Ctags为您提供了基本知识,但也有很多缺点。
- Taglist只是一个 Ctags 包装器,因此继承了它的大部分缺点(尽管它适用于列表声明)。
- cppcomplete根本没有按承诺工作,我无法弄清楚我做错了什么,或者它是否“正常工作”并且限制是设计造成的。
- OmniCppComplete似乎与cppcomplete有同样的问题,即自动完成不能正常工作。此外,该
tags
文件再次需要手动更新。
I'm aware of the fact that not even modern, full-blown IDEs offer good C++ code completion. That's why I've accepted Vim's lack in this area until now. But I think a fundamental level of code completion isn't too much to ask, and is in fact required for productive usage. So I'm searching for something that can accomplish at least the following things.
我知道即使是现代的、成熟的 IDE 也不能提供良好的 C++ 代码补全。这就是为什么直到现在我才接受 Vim 在这方面的不足。但我认为基本级别的代码完成并没有太多要求,实际上是生产使用所必需的。所以我正在寻找至少可以完成以下事情的东西。
Syntax awareness. cppcomplete promises (but doesn't deliver for me), correct, scope-aware auto-completion of the following:
variableName.abc variableName->abc typeName::abc
And really, anything else is completely useless.
Configurability. I need to specify (easily) where the source files are, and hence where the script gets its auto-completion information from. In fact, I've got a Makefile in my directory which specifies the required include paths. Eclipse can interpret the information found therein, why not a Vim script as well?
Up-to-dateness. As soon as I change something in my file, I want the auto-completion to reflect this. I do notwant to manually trigger
ctags
(or something comparable). Also, changes should be incremental, i.e. when I've changed just one file it's completely unacceptableforctags
to re-parse the whole directory tree (which may be huge).
语法意识。cppcomplete 承诺(但不为我提供)、正确的、范围感知自动完成以下内容:
variableName.abc variableName->abc typeName::abc
真的,其他任何东西都完全没用。
可配置性。我需要(轻松地)指定源文件的位置,以及脚本从哪里获取自动完成信息的位置。事实上,我的目录中有一个 Makefile,它指定了所需的包含路径。Eclipse 可以解释在其中找到的信息,为什么 Vim 脚本也不能解释?
与时俱进。一旦我更改了文件中的某些内容,我希望自动完成功能能够反映这一点。我不想要手动触发
ctags
(或一些类似)。此外,更改应该是增量的,即当我只更改一个文件时,重新解析整个目录树(可能很大)是完全不可接受的ctags
。
Did I forget anything? Feel free to update.
我忘记了什么吗?随意更新。
I'm comfortable with quite a lot of configuration and/or tinkering but I don't want to program a solution from scratch, and I'm not good at debugging Vim scripts.
我对相当多的配置和/或修补感到满意,但我不想从头开始编写解决方案,而且我不擅长调试 Vim 脚本。
A final note, I'd really like something similar for Java and C# but I guess that's too much to hope for: ctags
only parses code files and both Java and C# have huge, precompiled frameworks that would need to be indexed. Unfortunately, developing .NET without an IDEis even more of a PITA than C++.
最后一点,我真的很喜欢 Java 和 C# 类似的东西,但我想这太希望了:ctags
只解析代码文件,Java 和 C# 都有需要索引的庞大的预编译框架。不幸的是,在没有 IDE 的情况下开发 .NET比 C++ 更像是一种 PITA。
采纳答案by Valloric
Try YouCompleteMe. It uses Clang through the libclang interface, offering semantic C/C++/Objective-C completion. It's much like clang_complete, but substantially faster and with fuzzy-matching.
试试YouCompleteMe。它通过 libclang 接口使用 Clang,提供语义 C/C++/Objective-C 完成。它很像 clang_complete,但速度更快,并且具有模糊匹配。
In addition to the above, YCM also provides semantic completion for C#, Python, Go, TypeScript etc. It also provides non-semantic, identifier-based completion for languages for which it doesn't have semantic support.
除了上述之外,YCM 还为 C#、Python、Go、TypeScript 等提供了语义补全。它还为没有语义支持的语言提供了非语义的、基于标识符的补全。
回答by Konrad Rudolph
There's also clang_completewhich uses the clang
compilerto provide code completion for C++ projects. There's another question with troubleshooting hintsfor this plugin.
还有clang_complete使用clang
编译器为 C++ 项目提供代码完成。还有一个关于此插件的故障排除提示的问题。
The plugin seems to work fairly well as long as the project compiles, but is prohibitively slow for large projects (since it attempts a full compilation to generate the tags list).
只要项目编译,该插件似乎就可以很好地工作,但对于大型项目来说速度太慢(因为它尝试完整编译以生成标签列表)。
回答by Ric Tokyo
as per requested, here is the comment I gave earlier:
根据要求,这是我之前给出的评论:
have a look at this:
看看这个:
- Vim integration to MonoDevelopfor .net stuff at least..
- OmniCompletion
- Vim 集成到 MonoDevelop至少用于 .net 的东西......
- 全方位完成
this linkshould help you if you want to use monodevelop on a MacOSX
如果您想在 MacOSX 上使用 monodevelop,此链接应该对您有所帮助
Good luck and happy coding.
祝你好运,快乐编码。
回答by Konrad Rudolph
I've just found the project Eclimlinked in another question. This looks quite promising, at least for Java integration.
回答by romainl
I'm a bit late to the party but autocomplpopmight be helpful.
我参加聚会有点晚了,但autocomplpop可能会有所帮助。
回答by Ric Tokyo
回答by Johan
Did someone mention code_complete?
有人提到过code_complete吗?
But you did not like ctags, so this is probably not what you are looking for...
但是您不喜欢 ctags,所以这可能不是您要找的...