mmap.page

VIM Completion Configuration

Built-in

Vim has built-in support for completions in insert or replace modes. See :help ins-completion.

By default, Vim uses separate Emacs style key bindings (<C-x C-key>) for different kinds of completions.

There are two plugins to use a single Tab key for completions:

There is also AutoComplPop to automatically pop up completions.

VimCompletesMe

Why

Count source lines of code (VimScript comments start with "):

; cat supertab.vim | egrep -v '^("|([[:blank:]]*$))' | wc -l
923
; cat VimCompletesMe.vim  | egrep -v '^("|([[:blank:]]*$))' | wc -l
82

Period.

Configuration

Without any configuration, the Tab key will, depending on the context, offer:

With a b:vcm_tab_complete variable, you can set the Tab key to use the following type of completions:

If any of above types of completions fails to return any results, hitting Tab again will switch back to Vim’s local keyword completion.

You can set the b:vcm_tab_complete variable interactively, or in ~/.vimrc:

autocmd FileType text,markdown let b:vcm_tab_complete = 'dict'

AutoComplPop

Use Enter to commit completion. Use arrow keys (Up|Down) to select completions.

It works well for certain file types, while distracting on other types such as text.

External engine

YouCompleteMe

YouCompleteMe is a fast, as-you-type, fuzzy-search code completion engine. It has several completion engines:

YCM also provides semantic IDE-like features in a number of languages:

Tho downside is it consumes a lot of RAM.

neocomplete

neocomplete maintains a cache of keywords in the current buffer. It requires Vim 7.3.885+ with Lua enabled. It sometimes be slower than YCM, but requires much less RAM.

You can configure it to use Tab key to complete, and/or automatically pops up completion menu.

Conclusions