Autocompletion in Vim

121,333

Solution 1

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.

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.

Solution 2

There’s also clang_complete which uses the clang compiler to provide code completion for C++ projects. 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).

Solution 3

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

Good luck and happy coding.

Solution 4

I've just found the project Eclim linked in another question. This looks quite promising, at least for Java integration.

Solution 5

I'm a bit late to the party but autocomplpop might be helpful.

Share:
121,333

Related videos on Youtube

Konrad Rudolph
Author by

Konrad Rudolph

I’m a bioinformatician/scientist & software developer. I hold a PhD from the University of Cambridge and EMBL-EBI. I’ve dabbled in everything from biological research (mostly genomics and epigenetics) and statistical analysis (using R) to software development, both on the frontend (using e.g. HTML, JavaScript, WinForms, Swing) and the backend (using C++, Java, Python, Ruby, PHP, to name a few). [he/him] 💜 Sponsor me on GitHub if you would like to support what I’m doing here.

Updated on September 20, 2020

Comments

  • Konrad Rudolph
    Konrad Rudolph over 3 years

    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.

    I know about Ctrl+N, Exuberant Ctags integration, Taglist, cppcomplete and OmniCppComplete. 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. 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.

    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.

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

    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.

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

    • Shahbaz
      Shahbaz over 12 years
      It's been a long time since you asked this question, have you finally found a good one? I am asking because I don't see any accepted answers. Personally though I have to admit I resorted into prefixing my variables/functions. For example, all of them start with sh (meaning it's in my library) and followed by the abbreviation of my class. For example shP for Parser class. Then all you need to do is write shP and hit CTRL+p (or CTRL+n if you want) and get the class members from last use to first (or first to last if CTRL+n)
    • Konrad Rudolph
      Konrad Rudolph over 12 years
      @Shahbaz In fact, I’m convinced that there is no good enough solution at the moment. clang_complete is technically the most sound but prohibitively slow due to lack of caching the results and partial compilation. I have to admit that I haven’t tried all answers because some require a convoluted, time-consuming setup. I’ll hold my breath for a usable plugin now that clang finally allows developers to build ASTs from C++ sources (until now, there were no good free parsers for C++ available).
    • Jan Larres
      Jan Larres over 12 years
      Have you tried clang_complete recently? It can use libclang with caching now and thus should be faster.
    • Konrad Rudolph
      Konrad Rudolph over 12 years
      @Jan Thanks for the info. When I last tried it, libclang support was still sketchy. I should probably try again once I get the time.
    • Konrad Rudolph
      Konrad Rudolph over 11 years
      (Reason for edit rollback: product names aren’t code, they don’t belong formatted like this.)
  • Konrad Rudolph
    Konrad Rudolph almost 15 years
    This would be what I'm looking for, yes. Unfortunately, it only runs on Windows (I'm using OS X). Also, the last update seems to have been made around 2003. :-(
  • Ric Tokyo
    Ric Tokyo almost 15 years
    well you can get the source code :) if not that, the only thing I can think of is omnicompletion.. or have a look at this: ankitjain.org/blog/2007/06/30/integrating-vim-with-monodevel‌​op for .net stuff at least..
  • Konrad Rudolph
    Konrad Rudolph almost 15 years
    Ric, please provide your comment as two separate answers, they're invaluable, and I'd like to honour them properly! That said, MonoDevelop is unusable under OS X as of now, and I'm currently looking into OmniCppComplete.
  • Nils
    Nils over 13 years
    Lol this is windows only! :( Why should u want this on windows where u have VS.. I'm looking for a solution on Linux.
  • Ric Tokyo
    Ric Tokyo over 13 years
    Nils: Not everyone has access to Visual Studio, also alot of people have vi skills which they want to apply in the Windows environment. There was a port to Linux, but its currently down. In any case, what are you trying to achieve? are you sure you dont just need the default auto-complete functions? linux.org/docs/ldp/howto/C-editing-with-VIM-HOWTO/…
  • Pacane
    Pacane over 13 years
    Have you tested it? Seems interesting.
  • Konrad Rudolph
    Konrad Rudolph over 13 years
    @Pacane: no. I haven’t had to use Java in months and didn’t have spare time to experiment.
  • Drupad Panchal
    Drupad Panchal almost 13 years
    Eclim seems to be a great solution for Java, although Eclipse still remains a beast to load even in a headless setup
  • kizzx2
    kizzx2 over 12 years
    For Java, you can use Vrapper. I find that it's usually OK with superb auto-completion. For the occasional text-heavy editing, I can launch real Vim as an external tool.
  • dotoree
    dotoree over 12 years
    OmniCompletion link is broken
  • Lumi
    Lumi about 12 years
    The clang_complete plugin works nicely on Cygwin and Windows. Can't say anything about large projects because I don't have any. :)
  • dashesy
    dashesy over 11 years
    It seems clang_complete using libclang has caching now. This should be then the accepted answer. Have you tried clang_complete on Linux kernel? the best indexing I have seen for kernel is using Eclipse CDT, if clang_complete can handle kernel it should be able to complete just anything.
  • Konrad Rudolph
    Konrad Rudolph about 11 years
    In fact, I’m going to accept this solution. Finally a plugin that delivers. I’ve been using it for several days now. It only took four years to answer this question. ;-)
  • Cromulent
    Cromulent about 11 years
    clang_complete is quite simply the best Vim plugin I use.
  • Konrad Rudolph
    Konrad Rudolph about 11 years
    @Cromulent Ah, check YouCompleteMe, it’s much better.
  • Cromulent
    Cromulent about 11 years
    @KonradRudolph Thanks. I'll check it out.
  • static_rtti
    static_rtti almost 11 years
    To get this to work on Arch make sure you install "gvim" instead of "vim", even if you use the terminal version of vim.
  • statquant
    statquant almost 11 years
    awesome job with YouCompletMe valloric ! congrats
  • dashesy
    dashesy over 10 years
    This should be in standard package repositories with yum install vim-ycm. Great extension.
  • x-x
    x-x over 10 years
    Too bad YouCompleteMe is a complete PITA to install on Windows :(
  • rafee
    rafee over 10 years
    I suggest github.com/nosami/OmniSharpServer with YouCompleteMe for C#, as suggested above
  • user456584
    user456584 about 10 years
    @DrTwox From the readme: "YCM has no official support for Windows, but that doesn't mean you can't get it to work there. See the Windows Installation Guide wiki page. Feel free to add to it."
  • Robert S. Barnes
    Robert S. Barnes about 10 years
    Can YouCompleteMe handle / be used with the Linux kernel with all it's weird macro magic?
  • Abhinav Gauniyal
    Abhinav Gauniyal about 9 years
    @static_rtti , regarding Arch , why so?
  • static_rtti
    static_rtti about 9 years
    @AbhinavGauniyal : I don't remember. It may even be that my comment is no longer valid. Could you test and report back?
  • Abhinav Gauniyal
    Abhinav Gauniyal about 9 years
    @static_rtti It works , but only if I compile with my system version of clang. On installing with binaries that are supplied with YCM , server crashes frequently. I just asked thinking I might be missing something :p
  • becko
    becko almost 9 years
    Can I use this plugin even though I compile my project with gcc?
  • EntangledLoops
    EntangledLoops over 7 years
    This post should mention that you are the author, as this is borderline self-promotion (although I won't argue it answers the question, you should include a disclaimer nonetheless).
  • Sourav Mukherjee
    Sourav Mukherjee over 6 years
    When i type an object.methodName ycm shows all the methods instead of those inside the class. Is there any way to fix this ?
  • einpoklum
    einpoklum almost 3 years
    While YCM might be swell when it works, it has extremely onerous dependencies and will only work with the newest versions of vi. So, problematic.