Completion Methods in Vim

2015-10-10

The vim editor ships with several completion techniques:

Navigating through several completion matches is usually done using Ctrl-n (next match) and Ctrl-p (previous match). In addition to the completion techniques above, vim provides further completion methods. A complete list of completion methods can be retrieved inside vim via the command :help ins-completion. Vim plugins such as neocomplete enable you to customize the keyword completion. Besides the built-in completion methods, there are snippet plugins such as UltiSnips and neosnippet which allow you to insert code snippets after entering a snippet keyword and pressing a configurable key combination.

With this plethora of completion options comes the problem of remembering the key combinations for the different completion options for the various contexts. Therefore, it would be desirable if there was a single, easy to reach key which triggers a suitable completion method based on the context. This is where plugins such as supertab come in. Supertab allows you to use the tab key to trigger an appropriate completion method which it derives from the text preceding the cursor. Moreover, supertab enables completion chaining, thereby falling back to a different completion type, if one of the preferred completion methods returns no results. A disadvantage of supertab is that its context detection does not work well for some file types and is difficult to customize. Vim-clevertab is an easy to configure alternative to supertab allowing you to define a completion chain in a straightforward fashion. The only drawback of vim-clevertab that I encountered was that it lacked support for the useful neosnippet plugin which is why I decided to add support for it. The maintainer of vim-clevertab, Sebastian Grignoli, merged my changes into the main branch of the vim-clevertab plugin.

In conclusion, vim offers numerous completion options which can efficiently be managed using vim plugins such as supertab and vim-clevertab.