1

I'm currently switching to Vim as my main text editing tool and I try to investigate if it is possible to make Vim behave like VScode when it comes to autocompletion. I got really used to the way VScode manages this.

I work with JavaScript primarily, and when I use third party library, VScode is capable to analyse exports provided by external library. I've tried to capture this on attached screenshots: it knows that imported module has scaleLinear function in it. And when I use this function, VScode knows that returned value has domain, range, etc. methods in it.

I've tried to use YouCompleteMe and coc.vim plugins, but could not achieve desired behaviour.

enter image description here

enter image description here

1

What you want is to use a Language Server through the Language Server Protocol (LSP).

Read more about it on Wikipedia or on the official website.

As the Wikipedia article points out:

The Language Server Protocol was originally developed for Microsoft's Visual Studio Code and is now an open standard.

So what you get in VS Code is actually being backed by a language server. (In other words, at least in theory, all that information can be available to Vim as well.)

Things get a little more murky as you explore using LSP from Vim, since there are many competing plug-ins that can use an LSP (many with different levels of support, or different sets of features.) So you'll have to try them out and see which ones work best for you.

You can find a list of those plug-ins for Vim at the official LSP website. Probably worth checking are vim-lsp and LanguageClient-neovim, which were developed specifically for supporting the Language Server Protocol.

But you'll see other Vim plug-ins such as coc.nvim and ALE, which predate LSP or started with a different approach have also added support for LSP, so looking into those (and particularly LSP integration from them) might be worth it.

Finally, if you're using LSP, you'll also need a language server for your particular language (JavaScript in your case.) See the list of language server implementations for some you might want to try.

This is a fairly new area and there are quite a few moving parts, so expect it'll take quite a bit of experimentation, some research, you might find poor or lacking documentation and it's possible the end result is still far from what you expected. But this will be as close from VS Code as you can get, since in the essence that's what VS Code actually uses.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.