Hacker News new | past | comments | ask | show | jobs | submit login
YouCompleteMe, a Fast, As-You-Type, Fuzzy-Search Code Completion Engine for Vim (markovic.io)
427 points by syncontrol on Feb 5, 2013 | hide | past | web | favorite | 114 comments

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.

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

It doesn't really depend on MacVim, that's just a binary distribution of Vim for Macs that is proven to work.

Vim from Homebrew doesn't work though, something is wrong with the way Homebrew configures/builds Vim (don't know what though).

You can certainly build a Vim from source for Mac and have that work well with YCM, the only question is why would someone go through the trouble of doing so when MacVim does it for you.

Even if you prefer using Vim in the console and don't like the GUI, MacVim.app has a normal Vim binary inside it that you can call.

Vim from Homebrew + YouCompleteMe works for me.

* brew install vim

* alias vim="/usr/local/Cellar/vim/7.3.632/bin/vim"

* :BundleInstall 'Valloric/YouCompleteMe'

* Make the ycm_build directory:

    cd ~
    mkdir ycm_build
    cd ycm_build
* brew install cmake

* Run cmake from the ycm_build dir:

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

And boom, YouCompleteMe is running for me.

Works amazing. Always had a problem with having to press a button to autocomplete. The cognitive reflection of "okay, I want help completing this word" usually defeats the speed improvement for me.

> It doesn't really depend on MacVim, that's just a binary distribution of Vim for Macs that is proven to work.

Ah okay - the README gave me a very different impression. Either way using the packaged MacVim binary via the mvim script is preferable, for reasons you've elaborated on.

> why would someone go through the trouble of doing so when MacVim does it for you.

Commandline lovers love trouble, are often not found browsing .dmg offerings?

homebrew-built vim worked fine for me. I followed the manual steps.

No, don't make a symlink. A simple alias is less obstrusive:

    alias vim='/path/to/mvim -v'

An alias will only work with things that are using your shell with your configuration sourced. Things that merely use your PATH won't pick that up.

For the typical use of Vim, it's perfect:

    $ vim filename

It breaks down when you use it in other common ways, like from your git configuration.

You can't use

anyway in git: you must give it the full path.

No, just 'vim' itself is fine, if you have a 'vim' in your PATH.


What I usually do is maintain a set of symlinks in ~/bin/ (which is in my PATH) if they are not already in my PATH (or if I want them to override something else in my PATH, like HEAD builds of various things on occasion), and only use aliases to set default arguments (`ls --color=auto` for example).

No. On Mac OS X, using `vim` generally causes this error:

    error: There was a problem with the editor 'vi'
The full path must be used to get rid of it.

I do not use home brew or ports so is there any reason that this would not work with the default vim that ships with macos?

You need at least version 7.3 patch 584, which is fairly recent. You can check with :version.

Just wrote up Gentoo install at http://pastebin.ca/2311021

Urk. After using this awhile I don't like the context spam and have disabled it.

Interesting idea, I can see how people in .net who want to look up a little-used Windows API might like to use it being automatic, but the annoyance of the feature outweighs any benefit for my environment.

vi + console + syntax highlighting = my preference. Mind remains uninterrupted, focused, instantly aware of syntax errors, code structure. :)

newb here, i gotta ask: is there something like this for python/php/non-C languages? something that completes your elements etc..?

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.


Yeah, I went there.

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!

There's a lot of overlap between the two. I'd consider auto-complete.el as a more modern hippie-expand which also includes a nice GUI.

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

That emacs vs vim debate, here goes...

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.

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

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>

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.

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

Whether you're adding IDE features to vim or vim features to an IDE, you'll always going to have to live with compromises.

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)

> if you use Visual Studio, use viemu.

I recommend vsvim. It is open source and free where viemu costs $99.


I haven't used it but is PhpStorm no 'real' IDE for PHP? There's a vim plugin for various JetBrains products too (including PhpStorm) and it works well with IDEA.

I worked with Zend Studio around it's 5th release and it was quite ok. Don't know about now, though.

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

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?

autocomplop[1] is easier to install, but not as sophisticated. I just installed it to see if I like the idea of having completions pop up automatically.

[1] https://bitbucket.org/ns9tks/vim-autocomplpop/

ACP would be great if it weren't slow and dev-dead. Also doesn't fuzzy-match.

I forked autocomplpop a while back to fix a couple issues and make it easier to add new language support. Never noticed a speed issue. I always preferred acp vs the others due to its simplicity.


Oooh, nice to hear. I've done a bunch of mods to make ACP work with JS a while ago (https://github.com/romainl/dotvim/blob/master/bundle/autocom...) but I'll check your version.

It isn't slow, here. YMMV.

Aye. I remember having problems with autocomplop though when I had a rather large amounts of text open at once; YouCompleteMe seems like an improvement in that regard though. Handled

  `vim src/**/*.go`
quite nicely.

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.

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.

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.

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.

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.

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.

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.

It seems to be working with Java...with almost all the functionality eclipse's autocomplete has, as far as I can tell.

eclim works really well for me, though it may be a bit too powerful (i.e. it does everything eclipse does, which includes debugger).

Really? I found eclim to be quite slow when I was using it last year. I would wait one to two seconds for an autocomplete menu to pop up.

Fortunately I haven't had to do any Java recently.

Unfortunately I'm a IntelliJ IDEA guy, so configuring projects in eclipse just to use it in vim would be an overkill.

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.

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)."

No. It only uses keyword completion (`<C-n>`/`<C-p>`) for anything that is not C, C++, Obj-C.

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?

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.

Jedi-vim is not good enough because it's slow.

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.

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.

Having both python2 and python3 enabled in your Vim can lead to nasty results. I remember Vim used to crash if you source a python2 file into it (thus starting the python2 interpreter) and a python3 file some time later (thus also starting the python3 interpreter). They didn't seem to like existing in the same process.

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

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

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.

One can also take types into account for completion. There is a Scala Eclipse IDE plugin that does it: http://lara.epfl.ch/w/insynth (it's a research project).

Wow and it didn't cost $70? :)

That other text editor doesn't cost $70 to use either ;)

I juuuust switched from gVim to Sublime Text. Luckily I havent bought licsense yet :)

If you're any good with substitutions and regex in VIM you'll probably switch right back.

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

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.

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.

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.

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!

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 :(

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!

vim plugins are really easy to dash off and can emerge naturally from scratching one's own itches. So they tend to be developed by individuals more often than teams and there is unfortunately some tendency to make a new project rather than co-opting existing ones, particularly when it is performance sensitive as in this case - it may be simpler to just write one designed for performance than to try to retrofit better performance onto a design which isn't well cut out for it.

Does it work and is it fast with ctags?

Tried installing for 10 minutes. Awful documentation. Couldn't get it to work. Looks cool though.

Wow, I can't use this in Ubuntu because it requires Vim 7.3.584 and Ubuntu comes with 7.3.547...

You can, just follow these simple, but detailed instructions for Ubuntu users for upgrading vim: https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-... To not mess with system-installed vim: remove --prefix option and VIMRUNTIMEDIR, then build and install with sudo make install, which will put the files in /usr/local.

Why must Vim 7.3.584+?

Here's the FAQ straight from the docs:

Why does YCM demand such a recent version of Vim? ~

During YCM's development several show-stopper bugs where encountered in Vim. Those needed to be fixed upstream (and were). A few months after those bugs were fixed, Vim trunk landed the 'pyeval()' function which improved YCM performance even more since less time was spent serializing and deserializing data between Vim and the embedded Python interpreter. A few critical bugfixes for 'pyeval()' landed in Vim 7.3.584 (and a few commits before that).

Does anyone know of something similar but for all text on an OS? I.e. I find my self repeatedly typing in the same strings in a variety of applications (browser, editor, etc) - would love for an autocomplete app that is OS wide and learns from what I type.

What I want is an OS-level autocorrect like vim's abbreviations. I'm getting used to not having to care about making typos because they get fixed automatically.

This looks great. Non-semantic completions (for languages not covered by libclang) are very useful as well. I'm an emacs person and dabbrev-expand saves me a lot of typing in any mode.

I wish I had this plugin on emacs. So far, there's no "Command-T" nor this beautiful completion.

Yes, yes, there are hundreds of plugins that offer more powerful stuff.. but I miss so much Command-T.

"I can’t show a box with help text related to the function right next to the completion menu in Vim"

Couldn't you just populate quickfix instead?

That's still a window that's not right next to the completion menu. If I wanted to use a separate window far away from the menu, I'd use the 'preview' window that was designed for this (and YCM does use it, because there's nothing else on the table).

Have you checked the "balloon help" functionality? This was intended for use with mouse and windows for things like tooltips, but I think it may be general enough to expand for use you're looking for. My memory isn't so great but I fooled around with it a couple years ago; if you haven't checked it out you may want to. See ':h balloon'

I just looked back into use of the Vim 'balloon' feature. I think the ballooneval and balloonexpr would do the job fine, the only fly in the ointment is that the help window is tied to the mouse cursor position in two ways. First, the window can be triggered to appear only if the mouse cursor is on a character in the Vim window, not if it's in blank area (e.g., to right of text) or not in the Vim window at all. Second, the help window is always positioned with upper left corner at mouse cursor position. I don't think Vimscript offers any way to position the mouse cursor programmatically, which is what it would take to make Vim's balloons work for desired sort of help display. Perhaps Python could be used to position the mouse; might not be so bad given that Python is required for YCM already. Would require being able to map Vim text cursor position to global desktop xy grid (':winpos' might help) and move mouse cursor to it. . . (Or alternatively hack the Vim source to allow alternative coordinates (e.g., text cursor position) for display of balloon window.)

I get "libclang: crash detected during parsing" when used with clang 3.2. clang_complete with clang 3.1 worked fine.

Wow. This is really awesome, actually. I ended up having to compile a newer vim, but turns out it was worth it.

...not to annoy anyone or start a fwar, but:

Does anyone know how to get similar level completion in Sublime Text?

SublimeCodeIntel or SublimeClang work pretty well. He's working on native autocomplete and go to function in Sublime Text 3.

This is ready more or less built in to sublime 3. I saw the video on this and thought "oh neat, I've been doing that for a few days now in sublime text 3"

Just wondering, has anyone been able to get this working under Windows ?

Very cool. Has anyone gotten this working on Windows?

I haven't tried, but I've done everything possible to keep both the code and the build system cross-platform. I've written OSS cross-platform C++ code using Boost before (with CMake as the build system) and had it working on Windows, Mac, Linux and FreeBSD without modification. I've applied the same principles here, just haven't tested it on Windows or written docs on how to get it working there. But it's doable, certainly.

I'm having some issues compiling it on windows at the moment, specifically when compiling BoostParts. Saying "::hypot has not been declared". I'll update if I get it to compile


    #define hypot _hypot
from pyconfig.h (in my python include folder) got me to another hurdle

    function 'PyObject* boost::python::converter::do_return_to_python(char)' definition is marked dllimport
I have no idea what that means (never touched C++ in my life)

Letting this rest for now, I'd like to hear if others have any success

hmm... so tab cycles only one way, or is there a shift tab to move the other way in selections?

Shift-tab cycles the other way. Both the tab and the shift-tab mappings are configurable.

Note that shift-tab won't work in the console because the console won't pass that key combo to vim. Again, this can be remapped.

Is there a way to dismiss it without using the autocomplete?

ESC will do it. But you shouldn't really need to. You just continue typing and the menu goes away and pops back as needed. It does its best to be unobtrusive.

I was worried about interaction with Snipmate :) that's probably been accounted for, though. I'm really looking forward to trying this out.

If your going to use Snipmate, you may want to remap the completion selection key from TAB to something else (if you want to use TAB for Snipmate). See the docs for details.

Shift-tab works with SuperTab in the console.

Then it should work with YCM in your console as well (whether it works depends on the terminal emulator). A map is a map.

I like Fuzzy-search and FAST!!

Thank you, this is great.

The gif is cool!

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact