top | item 5169062

YouCompleteMe, a Fast, As-You-Type, Fuzzy-Search Code Completion Engine for Vim

427 points| syncontrol | 13 years ago |val.markovic.io | reply

114 comments

order
[+] dsrguru|13 years ago|reply
How to install (at least on Linux):

1. Install the Vundle plugin manager for Vim.

2. Add the line "Bundle 'Valloric/YouCompleteMe'" (without the double quotes) to your ~/.vimrc file.

3. Open Vim and run ":BundleInstall" without the quotes.

4. Install cmake if it's not already installed. In a temporary directory, run "cmake -G 'Unix Makefiles' . ~/.vim/bundle/YouCompleteMe/cpp" (without the quotes) to generate a Makefile and then run "make ycm_core" to build.

5. Open a file in Vim and start typing.

[+] justsee|13 years ago|reply
It depends on MacVim on OS X.

So for terminal Vim'ers:

1. copy the mvim script from MacVim to /usr/local/bin (or wherever)

2. ln -s /usr/local/bin/mvim vim (assuming you've ditched your old vim symlink)

Linking directly to the MacVim binary causes these sorts of issues[0].

[0] https://github.com/altercation/solarized/issues/60

[+] 11185d|13 years ago|reply
newb here, i gotta ask: is there something like this for python/php/non-C languages? something that completes your elements etc..?
[+] spullara|13 years ago|reply
This was state of the art emacs in 1997 when I was working on WebLogic. Though at the time it was called hippie-expand mode and it was in emacs.

http://emacswiki.org/emacs/HippieExpand

Yeah, I went there.

[+] S4M|13 years ago|reply
Thanks, I was wondering what where the plugins for emacs for autocomplete. How does HippieExpand compare to autocomplete.el? I'll try to test HippieExpand today!
[+] stewbrew|13 years ago|reply
IIRC hippie-expand requires users to press a keyboard shortcut (like omni-complete in vim). This plugin seems to always present a completion menu (updated after every keypress).
[+] inDigiNeous|13 years ago|reply
Just a note, you don't need Vundle to install this.

I have pathogen installed, which does basically the same thing as Vundle.

Just clone the git repo to your ~/.vim/bundle directory and continue compiling as instructed.

[+] syncontrol|13 years ago|reply
True, but I try to recommend a best practice (I never said Vundle was required, in fact the full Installation Guide mentions Pathogen as an option).
[+] eric-hu|13 years ago|reply
Instructions for an OS/X install with Brew, Macvim and Pathogen:

cd ~/.vim/bundle

git clone https://github.com/Valloric/YouCompleteMe.git

cd YouCompleteMe

mkdir ycmbuild

cd ycmbuild

# Do this only if you don't have cmake installed

brew update

brew install cmake

cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/cpp/

make ycm_core

<Restart vim>

[+] hakaaaaak|13 years ago|reply
I want to see developers who are experts in IDea, emacs, vim, etc. face off to code a variety of projects in several languages/frameworks side by side in each editor/IDE so we talk about the empirical differences. vim is a lot faster for many things, but I wonder how well it compares when you need to debug Java remotely (in a container on another server), for example.
[+] pekk|13 years ago|reply
If all you will do is write Java, and things like integrating remote debugging into your text editor are critical, and you don't care about vim's way of working, then you can find better options for that, definitely. IDEA is a great, well-polished specialist tool. You don't need a shootout to see this clearly.

Of course, you know that vim does not have remote Java debugging out of the box and that the Java community has long focused on IDEs, so this is not exactly a random benchmark you mention :)

vim is better for a more modular approach which is valuable when you will often need to change platforms, languages, tweak for a new workflow, etc. Know a good remote debugger? Sure, just use that...

[+] LinXitoW|13 years ago|reply
Whether you're adding IDE features to vim or vim features to an IDE, you'll always going to have to live with compromises.
[+] roel_v|13 years ago|reply
The vim editor is awesome, but all this 'bolt on a bunch of stuff to make vim more like an IDE' is misguided imo. If you use Java, use eclim for a vim-like experience in Eclipse; if you use Visual Studio, use viemu.

(that said, I still wrote a vim plugin to display the php manual function declaration in the status bar when you have your cursor nead the name of a vim function... but just because there is no 'real' IDE for php though)

[+] martinced|13 years ago|reply
"I want to see developers who are experts in IDea, emacs, vim, etc. face off..."

What makes you think they're mutually exclusive? For years I've ran Emacs and IntelliJ IDEA both configured to "synch files on change (on disk)" so that I could be synched between Emacs and IDEA. Both were (and still are) always open simultaneously.

Now in Eclipse you can use eclim which either turns Eclipse in server-mode or which allos to use vim as the text editor right in the middle of Eclipse.

There's also emacs-eclim: it's not as advanced but it has the merit to show that there's hope and light at the end of the tunnel.

Thing is: anyone efficient enough with vim/Emacs shall never find the "text editor" part of any idea to come anywhere close to vim/Emacs.

I need to remotely debug code? One shortcut and I'm under IntelliJ IDEA.

I need to efficiently edit files containting text, like source code files, one shortcut and I'm under Emacs...

I hope one day people writing IDEs will realize that no-one has ever written an IDE with a "text editor" that could match vim/Emacs and hence decide, from the start, to make the text editor pluggable.

[+] jlgreco|13 years ago|reply
Brilliant. My only concern is that the completion suggestions could cover text on other lines that I might be looking at, but I suppose this will serve to encourage me to stay out of insert mode unless necessary.

Edit: Compared to other Vim plugins the installation is a pain in the ass, but it really is as quick as it claims, even on my whoa-fully underpowered eeepc.

One suggestion: when I use SuperTab the name of the file that the suggestion is coming from appears to the right of the suggestion. That would be rather nice to have in this as well, if possible. Otherwise this is perfect, I think I'm finally done with SuperTab.

Edit 2 (sorry): This seems to be ignoring words that are in comments, and not completing anything when editing a comment. Is this toggle-able behavior?

[+] edanm|13 years ago|reply
Haven't had a chance to try this yet, but I can definitely say that this was a serious sore spot for vim. AutoComplPop is great (and is what I use), but it lacks Fuzzy Search which is very important to me. I tried installing NeoComplCache, but even after spending a lot of time on it, couldn't get it working properly - plus, it slowed down vim, by a LOT. I'm talking, opening a buffer took a visible amount of time.

If this plugin works as well as advertised, I'll be extremely happy.

[+] gcr|13 years ago|reply
Want to hear a secret from an emacs user?

It's almost just as bad over here. I've got maybe 20 lines to try and get this working in my .emacsrc. It's like layers of fossils; first I have a few commented lines fighting through the hippie-expand era, then a few more from the CEDET age, and gobs and gobs of elisp to try and cobble together auto-complete into completion, but even now it doesn't always work right for most of my languages. Maybe I'm just doing it wrong.

One thing that does work excellently is ido for opening files. If you're a vim developer, you should really rip off ido.

[+] MindTwister|13 years ago|reply
I second that, NeoComplCache is just too slow, I had issues where it simply hung vim for 2-3 seconds every time I tried to complete something, completely negating any speedup I might get from completing.
[+] njharman|13 years ago|reply
Cool, but.

Almost all the tools (shells, editors, sql clients) I use; either have (or I made to have) tab completion. This has been true to various degrees for 20years. Tab key to complete is utterly ingrained in my muscle memory.

And, the constantly on, constantly changing completions "suggestions" are utterly distracting.

Would like to see the "engine" plugged into standard vim completion (omnicomplete).

People who think vim completion is poor need to checkout supertab, jedi-vim, and language specific plugins such as python_calltips.

[+] syncontrol|13 years ago|reply
To each his own, I personally love it. :)

There's been a few requests for keeping the semantic completion engine but turning off the identifier-based engine (this is the "always-on" part) so the feature will be implemented some time soon.

[+] krzyk|13 years ago|reply
It's a pity that it doesn't support Java, it's more or less also a C family language (if one puts Objective-C and C++ in same bucket as pure C).

Or maybe someone tried it in Java?

I would really like to have better support for Java in vim(just editing and code completion, I don't debugger in vim). Do you know some useful plugins for this? I tried several (I don't remember the names) and I'm back to old omnicomplete that's in vim.

[+] prawks|13 years ago|reply
This is because this plugin employs clang to gather information for autocomplete.

I'm curious to find out how much effort it would take to extend this to other compiled languages. I don't know enough about javac or GCJ to say.

[+] dhruvmittal|13 years ago|reply
It seems to be working with Java...with almost all the functionality eclipse's autocomplete has, as far as I can tell.
[+] Anderkent|13 years ago|reply
eclim works really well for me, though it may be a bit too powerful (i.e. it does everything eclipse does, which includes debugger).
[+] M4v3R|13 years ago|reply
That looks really great! Does it work with PHP? That's my tool as of now, soI would really appreciatedif it could provide suggestions for it.
[+] elisee|13 years ago|reply
Yes, quoting from the article: "All of the above works with any programming language because of the identifier-based completion engine. It collects all of the identifiers in the current file and other files you visit and searches them when you type (identifiers are put into per-filetype groups)."
[+] johncoltrane|13 years ago|reply
No. It only uses keyword completion (`<C-n>`/`<C-p>`) for anything that is not C, C++, Obj-C.
[+] timc3|13 years ago|reply
How does this compare to Jedi Vim ( https://github.com/davidhalter/jedi-vim ) for Python completion?

This obviously looks better from a cross language point of view, but I wonder also how well the indexing works?

[+] johncoltrane|13 years ago|reply
YCM doesn't work for anything other than C,C++,Obj-C. Well, it does keyword completion (`<C-n>`/`<C-p>`) but that's not very useful.
[+] UncleBill|13 years ago|reply
Jedi-vim is not good enough because it's slow.
[+] s00pcan|13 years ago|reply
I ran into a couple of issues while building vim with python support (which I haven't needed until now). I have arch linux and python3 was symlinked to /usr/bin/python, the build script cached this and once I fixed the symlink to point to /usr/bin/python2 it was still giving an error. I manually fixed the check in the build script, compiled, but then the plugin didn't recognize +python/dyn so I had to rebuild without python3 support. It seems to be working now and I'm compiling ycm_core. Also, if you're going to be building vim anyway, --enable-rubyinterp and check out the command-t plugin.
[+] jack12|13 years ago|reply
On Arch the 'gvim' package also includes a more featureful console vim, including python (2, not 3) support built-in. The downside is that the dependencies for gvim include GTK and a good chunk of X11.

If you do need a console-only vim on arch, it's probably best to build it by hand as you did, since the PKGBUILD in abs for the vim/gvim/vim-runtime set of packages doesn't lend itself well to custom builds.

[+] dfbrown|13 years ago|reply
One thing I miss form clang_complete is its snippet support for functions [0]. With clang_complete you could set it up so when you autocompleted a function, it would generate a temporary snippet in your favourite snippet engine (ultisnips, snipmate, etc) so you could jump between the parameters of the function.

[0] https://github.com/Rip-Rip/clang_complete/blob/master/doc/cl...

[+] 6ren|13 years ago|reply
aside: What about context sensitive/markov completion, backed by say github/google code? And if the prediction was certain enough, offer multi-line completions. This would be helpful in languages/situations that need boilerplate for common tasks, that you'd usually google-paste.

Or maybe howdoi-based completion http://news.ycombinator.com/item?id=5027021

[+] seanmcdirmid|13 years ago|reply
One of the projects I dream about doing is to use github/google/... code as a corpus to feed into a deep neural network, which could then perhaps do what you are talking about. However, more work needs to be done on how to represent the code and train the models.

There has been lots of work on intelligent code completion in the SE community. It doesn't seem to be very effective yet, however.

[+] account_taken|13 years ago|reply
Wow and it didn't cost $70? :)
[+] ZaneA|13 years ago|reply
For those have a project with an existing .clang_complete file (used to pass options to the compiler with the clang_complete Vim plugin), this gist [1] will allow you to reuse that file with YouCompleteMe. Better I suppose would be a patch to detect a .clang_complete file in YCM directly...

[1] https://gist.github.com/ZaneA/4719983

[+] cjh_|13 years ago|reply
Very cool, for me the simple fact that this is searching for a subsequence rather than a prefix makes this awesome.

I am too used to IDEs only using prefix, which is often useless to me (I remember the 2nd word but that is it, time to google).

EDIT: I find the idea of a helper window really neat (display documentation, argument names and types, etc.), too bad the vim API isn't there yet.

[+] syncontrol|13 years ago|reply
You can still get such a helper window, just not in a convenient place. Vim's 'preview' window is there to show such information (docs, arg names and types), but it pops up at the top of the screen instead of right next to the completion window.

YCM will feed information to the 'preview' window by default (you just need to have 'preview' in Vim's 'completeopt' option). See the docs.

[+] goatslacker|13 years ago|reply
What are the advantages of using YCM (and its complicated install) vs something like supertab if you're not a C/C#/Objective-C programmer?

The website doesn't offer a good explanation. From the docs:

  SuperTab I have limited experience with, 
  but from I understand, it does a half-decent 
  job at #4, much like neocomplcache.
[+] gws|13 years ago|reply
A question for syncontrol if you are not tired answering comments yet :)

YCM does not seem to integrate with snippets like NeoComplCache does, right? Do you plan to do that in the future? Are there reasons to switch from NeoComplCache if you don't program in languages for which a semantic engine is available?

Thank you for building this, awesome work!

[+] toonse|13 years ago|reply
I like the concept and awesome for the fellow to release it... however in the past the following have seriously messed up any attempts of mine to get sensible autocompletion in vim: working in cygwin, projects > 2mil lines of code, and varying types of build infrastructures.

I'll try it, but I'm not hopeful :(

[+] veneratio|13 years ago|reply
I like it quite a bit, and I think it's a bit better than the other options (a few of which I've tried). My only question remaining is why can't the others be updated and improved? Maybe someone with a bit more knowledge of the "culture and history" can explain. Great piece of software, though!