Select Page

Introduction

Vim is an old gold. And like every other good ol’ thing, Vim has its flaws too. Even so, don’t neglect the fact that Vim is extensible – far more extensible than you might anticipate. Vim, despite its growing age, has auto completion features built into it, which is good enough for the average user. If it does not satisfy you, Vim plugins have all your answers.

If autocomplete makes you happy enough, great. I’m happy for you too. But our exposition of autocompletion may not make every other developer delighted. Because there are many coders who’ve just migrated from VS Code to Vim, but are mourning the absence of VS Code’s biggest feature, Intellisense. It is more than just autocompletion. Vim may not be able to cover up all the features of it, but there’s at least one plugin that will get you as far as you can go about Intellisense in Vim.

But first, let us cover up some basic autocompletion.


Using Vim’s built-in Autocompletion like Intellisense

Using Vim’s built in auto completion could be a bit of work to set up properly, but once you do it right, it’ll work just as good as any other. It contains enough autocompletion snippets to satisfy the average users. So how do you enable it? First, you need to add the following lines in your .vimrc file, based on the programming language for which you want the auto completion to work. For example, if you want to autocomplete html files, you’d add the following in your .vimrc:

autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

Now while you’re inside an html file, writing some code, you can then bring out a pop up menu for autocompletion, by pressing Ctrl + X and then Ctrl + O in a sequence. I know it seems a little inconvenient, but we’ll get to making it shorter and more approachable as we proceed. For now, look at the following gif to understand how it actually works:

This way, you can make use of Vim’s built in autocompletion, as long as you don’t need an advanced snippet not listed among the presented commands. You can also create your own snippets using Vim Abbreviations, but that’s off for a later day. Let us now instead simplify the Ctrl + X and Ctrl + O sequence.

You can use a key mapping to save yourself a few keystrokes, and can assign a key for the task you like and something that is not assigned already by other commands. I like to set my one to the <F5> key. Here’s how:

inoremap <F5> <C-x><C-o> 

Now I can only press <F5> while I’m in Insert Mode and write some code, to bring up an autocomplete menu without needing to tire my fingers. Why not try it out yourself to see how it works?

For your convenience, I’m listing down a few autocommands for the commonly used programming languages one might use auto completion with. If the one you use isn’t listed here, you may find luck checking the documentation, or elsewhere.

Python:

 autocmd FileType python set omnifunc=pythoncomplete#Complete

Javascript:

autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS

HTML:

autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

CSS:

autocmd FileType css set omnifunc=csscomplete#CompleteCSS

XML:

autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags

PHP:

autocmd FileType php set omnifunc=phpcomplete#CompletePHP

C:

autocmd FileType c set omnifunc=ccomplete#Complete

Autocompletion Plugins for Vim that are like Intellisense

There are quite a lot of autocomplete plugins available for Vim. But the simplest yet the most useful one is the Mucomplete plugin. The special thing about this plugin is that it is the most lightweight among all. Why? Because all it does is automate the pop up of autocomplete menu of Vim readily built-in one. As we’ve seen in the previous section, the pop up menu wouldn’t appear automatically unless you press a key or something. But Mucomplete automates it so you won’t need to press anything for the pop-up to appear, like it usually does elsewhere. SImply install it by using your favorite plugin manager, and refer to its documentation to learn about all the settings you could use along with it.

Another plugin that really does a great job is the Deoplete plugin. It does not have a lot of features like VS Code’s Intellisense, but it does have a plethora of cool features you could make use of. Visit their github page to learn more about the plugin.


coc.nvim | True Vim Intellisense

The coc.nvim plugin (short for Conquer of Completion), is the closest a Vim plugin can get to VS Code’s Intellisense language server support, and is a joy to use. The NodeJS backend it uses is fast and reliable, with support for all the LSP features the Neovim fork of Vim has to offer.  It does still have a few shortcomings, like quite a few users have faced issues when trying to use it with Python. Nevertheless, it still stands as a great Vim plugin you could add up to your plugin list!

The coc.nvim plugin (short for Conquer of Completion), is the closest a Vim plugin can get to VS Code’s Intellisense language server support, and is a joy to use. The NodeJS backend it uses is fast and reliable, with support for all the LSP features the Neovim fork of Vim has to offer.  It does still have a few shortcomings, like quite a few users have faced issues when trying to use it with Python. Nevertheless, it still stands as a great Vim plugin you could add up to your plugin list!

Plug 'neoclide/coc.nvim', {'branch': 'release'}

Once you’ve done that, you now need to install the necessary coc extensions required for the plugin to communicate with the LSP and make the autocompletion work. Simply do this by using the below command in Vim Command Mode:

:CocInstall coc-json coc-tsserver

You are now good to go! To further personalize the plugin for yourself, you may want to refer to their github page to learn about the different settings you could incorporate with the plugin to better match your workflow. It goes long so it’s best not to discuss it here! The Readme section in their github page does a great job already at explaining how it works.


Conclusion

Yes. I do agree that Vim lacks a bit in autocompletion as compared to that of VS Code and others like Sublime. But it does not have to be. Why? Because Vim is more about the manipulation of text. It started initially with that in mind. But as it grew on, people started using it more often in all things they possibly could, simply because they liked to use it. However, it is not to be underestimated anyway because the fact that it is open source allows developers from all around the world to contribute plugins that work just the way you need them to, and the ones available are not to be misjudged by any means. So why be shy to say it yourself? “Long live the mighty Vim!”