Can I add a set of words to the Vim autocomplete vocabulary?

You can use abbreviations in your ~/.vimrc file for just a couple of words:

:abbr supe superuser
:abbr autoc autocomplete
:abbr que question

These will auto-complete after pressing Space or Enter. So if you typed que then pressed Space or Enter it would finish the word "question" for you.

If you are adding a lot and want this interface:

alt text

You can use dictionaries. Simply set up a file with a word on each line, then in your .vimrc add a line like this:

set dictionary+=/home/john/dict.txt

Replace the path with your dictionary file's location. You can then use Ctrl + x and Ctrl + k to bring up the suggestions. Ctrl + n and Ctrl + p to select the next/previous out of multiple selections.


The "sources" to the regular autocomplete (the one you get from Ctrl+N) are taken from the complete option (see :h 'complete') The default is

complete=.,w,b,u,t

which means

  1. . scan the current buffer
  2. w scan buffers from other windows
  3. b scan other loaded buffers that are in the buffer list
  4. u scan the unloaded buffers that are in the buffer list
  5. t tag completion

you can add your own dictionary with

set complete+=k~/.vim/keywords.txt

and add the keywords one per line in ~/.vim/keywords.txt. This way you can access the completions directly with Ctrl+N (there's no need to explicity invoke dictionary completion with Ctrl+X, Ctrl+K). I found this to be specially useful for code completions where I have all the common used function names in keywords.txt