Completion Methods in Vim
The vim editor ships with several completion techniques:
- Keyword in dictionary (Ctrl-x Ctrl-k)
- Keyword in complete (Ctrl-n or Ctrl-p)
- Custom keyword completion (Ctrl-x Ctrl-u)
- Omni completion (Ctrl-x Ctrl-o)
- File name completion (Ctrl-x Ctrl-f)
- Line completion (Ctrl-x Ctrl-l)
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.