简体   繁体   English

Vim中的自动完成

[英]Autocompletion in Vim

In a nutshell, I'm searching for a working autocompletion feature for the Vim editor. 简而言之,我正在为Vim编辑器搜索一个有效的自动完成功能。 I've argued before that Vim completely replaces an IDE under Linux and while that's certainly true, it lacks one important feature: autocompletion. 我之前曾经说过 ,Vim完全取代了Linux下的IDE,虽然这确实是正确的,但它缺少一个重要特性:自动完成。

I know about Ctrl + N , Exuberant Ctags integration , Taglist , cppcomplete and OmniCppComplete . 我知道Ctrl + NExuberant Ctags集成TaglistcppcompleteOmniCppComplete Alas, none of these fits my description of “working autocompletion:” 唉,这些都不符合我对“工作自动完成”的描述。

  • Ctrl + N works nicely (only) if you've forgotton how to spell class , or while . 如果您忘记了如何拼写class ,或者while拼写classwhile Ctrl + N可以很好地(仅)工作。 Oh well. 那好吧。
  • Ctags gives you the rudiments but has a lot of drawbacks. Ctags为您提供了基本知识,但有许多缺点。
  • Taglist is just a Ctags wrapper and as such, inherits most of its drawbacks (although it works well for listing declarations). Taglist只是一个Ctags包装器,因此继承了它的大多数缺点(尽管它适用于列表声明)。
  • cppcomplete simply 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. cppcomplete根本没有按照承诺的方式工作,我无法弄清楚我做错了什么,或者它是否正确“工作”并且限制是设计的。
  • OmniCppComplete seems to have the same problems as cppcomplete, ie auto-completion doesn't work properly. OmniCppComplete似乎与cppcomplete具有相同的问题,即自动完成无法正常工作。 Additionally, the tags file once again needs to be updated manually. 此外, tags文件再次需要手动更新。

I'm aware of the fact that not even modern, full-blown IDEs offer good C++ code completion. 我知道即使是现代的,全面的IDE也不能提供良好的C ++代码完成。 That's why I've accepted Vim's lack in this area until now. 这就是为什么我直到现在才接受Vim在这方面的不足。 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. 所以我正在寻找能够完成以下任务的东西。

  • Syntax awareness . 语法意识 cppcomplete promises (but doesn't deliver for me), correct, scope-aware auto-completion of the following: cppcomplete promises(但不会为我提供),正确,范围感知自动完成以下内容:

     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. 事实上,我的目录中有一个Makefile,它指定了所需的包含路径。 Eclipse can interpret the information found therein, why not a Vim script as well? Eclipse可以解释其中的信息,为什么不是Vim脚本呢?

  • Up-to-dateness . 最新的 As soon as I change something in my file, I want the auto-completion to reflect this. 一旦我在文件中更改了某些内容,我希望自动完成功能能够反映出这一点。 I do not want to manually trigger ctags (or something comparable). 不想手动触发ctags (或一些类似)。 Also, changes should be incremental , ie when I've changed just one file it's completely unacceptable for ctags to re-parse the whole directory tree (which may be huge). 此外,更改应该是增量的 ,即当我只更改一个文件时, 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. 最后一点,我真的喜欢类似于Java和C#的东西,但我想这太过于希望了: ctags只解析代码文件,Java和C#都有大量的预编译框架需要编制索引。 Unfortunately, developing .NET without an IDE is even more of a PITA than C++. 不幸的是,在没有IDE的情况下开发.NET甚至比C ++更像是PITA。

Try YouCompleteMe . 试试YouCompleteMe It uses Clang through the libclang interface, offering semantic C/C++/Objective-C completion. 它通过libclang接口使用Clang,提供语义C / C ++ / Objective-C完成。 It's much like clang_complete, but substantially faster and with fuzzy-matching. 这很像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等提供语义完成。它还为没有语义支持的语言提供非语义,基于标识符的完成。

There's also clang_complete which uses the clang compiler to provide code completion for C++ projects. 还有clang_complete ,它使用clang编译器为C ++项目提供代码完成。 There's another question with troubleshooting hints for this plugin. 此插件的故障排除提示还有另一个问题。

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). 只要项目编译,插件似乎工作得相当好,但对于大型项目来说速度过慢(因为它尝试完全编译以生成标记列表)。

as per requested, here is the comment I gave earlier: 根据要求,这是我之前给出的评论:

have a look at this: 看看这个:

this link should help you if you want to use monodevelop on a MacOSX 如果您想在MacOSX上使用monodevelop, 此链接应该可以帮助您

Good luck and happy coding. 祝你好运,编码愉快。

I've just found the project Eclim linked in another question . 我刚刚在另一个问题中发现了Eclim项目的链接。 This looks quite promising, at least for Java integration. 这看起来很有希望,至少对于Java集成而言。

我参加聚会有点晚了,但autocomplpop可能会有所帮助。

is what you are looking for something like intellisense? 你正在寻找像intellisense这样的东西?

insevim seems to address the issue. insevim似乎解决了这个问题。

link to screenshots here 链接到此处的屏幕截图

Did someone mention code_complete? 有人提到code_complete吗?

But you did not like ctags, so this is probably not what you are looking for... 但你不喜欢ctags,所以这可能不是你想要的......

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

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