
YouCompleteMe, a Fast, As-You-Type, Fuzzy-Search Code Completion Engine for Vim - syncontrol
http://val.markovic.io/blog/youcompleteme-a-fast-as-you-type-fuzzy-search-code-completion-engine-for-vim
======
dsrguru
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
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>

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

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

------
spullara
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
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!

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

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

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

~~~
roel_v
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)

~~~
dlebech
> if you use Visual Studio, use viemu.

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

[http://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-...](http://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-46ca-8fe1-0e90e3f79329)

------
jlgreco
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?

~~~
gurraman
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/>

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

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

<https://github.com/eikenberry/acp>

~~~
johncoltrane
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...](https://github.com/romainl/dotvim/blob/master/bundle/autocomplpop/autoload/acp.vim#L130))
but I'll check your version.

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

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

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

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

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

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

------
s00pcan
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
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
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...](https://github.com/Rip-
Rip/clang_complete/blob/master/doc/clang_complete.txt#L320)

------
6ren
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
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
Wow and it didn't cost $70? :)

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

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

------
ZaneA
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_
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
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
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
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
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
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!

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

------
gbog
Does it work and is it fast with ctags?

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

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

~~~
paweln
You can, just follow these simple, but detailed instructions for Ubuntu users
for upgrading vim: [https://github.com/Valloric/YouCompleteMe/wiki/Building-
Vim-...](https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-
source) 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.

~~~
UncleBill
Why must Vim 7.3.584+?

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

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

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

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

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

------
niggler
"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?

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

~~~
hsitz
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'

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

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

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

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

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

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

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

------
jonahx
Very cool. Has anyone gotten this working on Windows?

~~~
MindTwister
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

~~~
MindTwister
Removing

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

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

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

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

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

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

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

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

------
UncleBill
I like Fuzzy-search and FAST!!

------
owenjones
Thank you, this is great.

------
binarydreams
The gif is cool!

