YouCompleteMe (YCM) is really an awsome plugin. But today this blog post is not about completion support, it’s about YCM’s FixIt feature. If you are developer and have seen already compiler errors like this:

expected ';' at end of declaration

then I’m sure you also thought already: “If the compiler knows already the solution for the problem, why it can’t fix it automatically?’‘ Well, at least you might think so when using an IDE like Visual Studio.

As a Vim user it is more obvious that compiler and editor are two separate things and the compiler can’t fix it. But Vim with YCM can do exactly that. The command :YcmCompleter FixIt does exactly what we want. YCM shows the capability of doing so by adding the text (FixIt) to the error message. If you map this command to a keyboard shortcut like the following you can fix those issues with a single keypress:

" Apply YCM FixIt
map <F9> :YcmCompleter FixIt<CR>

Here is a short video to demonstrate the feature (click on the GIF to show in full size): ycm_syntax


Comments

comments powered by Disqus