vimtricks.wiki Concise Vim tricks, one at a time.

How do I autocomplete words from a dictionary file while typing in insert mode?

Answer

<C-x><C-k>

Explanation

Vim's insert-mode completion system includes dictionary lookup via <C-x><C-k>. Once you configure a dictionary file, you can complete words from it while typing — useful for prose writing, documentation, or any context where a large word list improves accuracy.

How it works

First, point Vim at a dictionary file:

:set dictionary=/usr/share/dict/words

Then in insert mode:

  1. Type the beginning of a word
  2. Press <C-x><C-k> to open the completion menu
  3. Use <C-n> / <C-p> to cycle through matches
  4. Press <C-y> or <CR> to accept a suggestion

Example

With the dictionary set, in insert mode:

Type: extra
Press: <C-x><C-k>
Menu shows: extraordinary, extravagant, extraterrestrial...

Navigate with <C-n> / <C-p>, then <C-y> to confirm.

Tips

  • Add multiple dictionaries: :set dictionary+=/path/to/custom.txt
  • On Linux/macOS, /usr/share/dict/words is usually available without setup
  • Add set complete+=k to your config so dictionary words appear in the default <C-n> completion too
  • For spell-correction-based completion, use <C-x>s instead
  • Combine with spelllang for language-specific dictionaries: :set spelllang=en

Next

How do I refresh the diff highlighting in Vim when it becomes stale after editing?