Setting up various IDE-like autocompleter in vim is painful until I met LanguageClient-neovim.

First, Disclaimer

I've been using Shougo's completion plugin ever since neocomplete (during the ancient vim time). Now in neovim, it has its dark form. If you are using other completion plugins like ncm2, this post might not be the case.

Language Server Protocol

If you ask what changed my impression of Microsoft, I'd answer this Language Server Protocol as one. From the official page, you could see so far many programming languages and DSL are onboard! Even though vscode still takes first class seat, I'm sure we'll see more powerful standalone servers coming up. Wow, you could even get a server for GLSL. No complaints anymore!

So Goodbye? Eclim, Tern.js and ...

That means whenever I need to work on a new language in vim, I no longer need to search that particular deoplete plugins and make it work after hours due to dependencies and .vimrc configuration. Installing completion engine dependencies is tedious: I still remember tern.js was not friendly and Eclim bundled with the huge Eclipse GUI family sale is quite tough. They lack of a universal language protocol standard. Even you succeed to make it work, after, you also need to weak key bindings for each of them.

Now with LanguageClient-neovim, I just install the servers (Note: not all of them are out of box but doable and only one time effort) and tell vim where their binaries are. I have freedom to choose any servers I like and freedom to pick up any editors/clients. I've tried out 4 languages so far: Java, Javascript, C++ and Python. They are working amazingly well. Let's see how much work to happiness:

Java

From the document, you feel you have to build either eclipse.jdt or javac based ls. However, for eclipse.jdt they have prebuilt versions to download here! So download and untar, and then follow the script.

Python

Simply run

pip install python-language-server

figure out your pyls binary path and you are done!

Javascript

Same as Python, you just need to

npm install javascript-typescript-langserver

and find the binaries.

C++

If you choose clang ([which you probably do]({% post_url 2018-08-11-clang-llvm %})), you just need to install clang with extra tools in box as in this tutorial. Although signature has an issue, but I believe community will solve it soon.

To Sum Up

After installing these servers, you just need a few lines in your vim plugins settings like here.

Easy piece, right? No?! Okay, if you enjoy a bit more automation, I have a script to deploy servers in my dotfile environment, you could adapt and make it yours.

Other Finding

At this stage, even not fully convinced but I found coc.nvim as yet another completion plugin seems to adapt all vscode language-service extensions to vim. If you like more vscode like features and don't have time to install each individual server, you might consider giving it a try. It seems to be still in heavy development. I chose to give it a little bit more time until I get tired of this LanguageClient plugin.

Meanwhile, while we wait, neovim is working on more native lsp support here.

...