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:
- Type the beginning of a word
- Press
<C-x><C-k>to open the completion menu - Use
<C-n>/<C-p>to cycle through matches - 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/wordsis usually available without setup - Add
set complete+=kto your config so dictionary words appear in the default<C-n>completion too - For spell-correction-based completion, use
<C-x>sinstead - Combine with
spelllangfor language-specific dictionaries::set spelllang=en