Vim 中的自动完成 [英] Autocompletion in Vim

查看:32
本文介绍了Vim 中的自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,我正在为 Vim 编辑器寻找工作自动完成功能.我之前争论过 Vim 完全取代了 Linux 下的 IDE,而那是没错,它缺少一项重要功能:自动完成.

In a nutshell, I'm searching for a working autocompletion feature for the Vim editor. I've argued before that Vim completely replaces an IDE under Linux and while that's certainly true, it lacks one important feature: autocompletion.

我知道 Ctrl+N丰富的 Ctags 集成标签列表cppcompleteOmniCppComplete.唉,这些都不符合我对工作自动完成"的描述:

I know about Ctrl+N, Exuberant Ctags integration, Taglist, cppcomplete and OmniCppComplete. Alas, none of these fits my description of "working autocompletion:"

  • Ctrl+N 效果很好(仅)如果您忘记了如何拼写 class,或者while.哦,好吧.
  • Ctags 为您提供了基本知识,但也有很多缺点.
  • Taglist 只是一个 Ctags 包装器,因此继承了它的大部分缺点(尽管它适用于 listing 声明).
  • cppcomplete 根本没有按承诺工作,我无法弄清楚我做错了什么,或者它是否正常工作"并且限制是设计的.
  • OmniCppComplete 似乎与 cppcomplete 存在相同的问题,即自动完成无法正常工作.此外,tags 文件再次需要手动更新.
  • Ctrl+N works nicely (only) if you've forgotton how to spell class, or while. Oh well.
  • Ctags gives you the rudiments but has a lot of drawbacks.
  • Taglist is just a Ctags wrapper and as such, inherits most of its drawbacks (although it works well for listing declarations).
  • 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.
  • OmniCppComplete seems 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.

我知道即使是现代的、成熟的 IDE 也没有提供良好的 C++ 代码补全功能.这就是为什么直到现在我才接受 Vim 在这方面的不足.但我认为代码完成的基本水平并没有太多要求,实际上是生产使用所必需的.所以我正在寻找至少可以完成以下事情的东西.

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.

  • 语法意识.cppcomplete 承诺(但不为我提供)、正确的、范围感知自动完成以下内容:

  • 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.

可配置性.我需要(轻松地)指定源文件的位置,以及脚本从何处获取其自动完成信息的位置.事实上,我的目录中有一个 Makefile,它指定了所需的包含路径.Eclipse 可以解释其中的信息,为什么 Vim 脚本不能?

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?

及时更新.一旦我更改了文件中的某些内容,我希望自动完成功能能够反映这一点.我不想想手动触发ctags(或类似的东西).此外,更改应该是增量,即当我只更改一个文件时,ctags 重新解析整个目录树是完全不可接受的(可能很大).

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). Also, changes should be incremental, i.e. when I've changed just one file it's completely unacceptable for ctags to re-parse the whole directory tree (which may be huge).

我忘记了什么吗?随时更新.

Did I forget anything? Feel free to update.

我对大量配置和/或修补工作感到满意,但我不想从头开始编写解决方案,而且我不擅长调试 Vim 脚本.

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.

最后一点,我真的很喜欢 Java 和 C# 类似的东西,但我想这太希望了:ctags 只解析代码文件,Java 和 C# 都有庞大的预编译框架这将需要被索引.不幸的是,在没有 IDE 的情况下开发 .NET 更像是一种 PITA,而不是C++.

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 IDE is even more of a PITA than C++.

推荐答案

尝试 YouCompleteMe.它通过 libclang 接口使用 Clang,提供语义 C/C++/Objective-C 完成.它很像 clang_complete,但速度要快得多,而且具有模糊匹配.

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.

除上述之外,YCM 还为 C#、Python、Go、TypeScript 等提供语义补全.它还为没有语义支持的语言提供基于标识符的非语义补全.

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.

这篇关于Vim 中的自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆