How do I complete words using a thesaurus for synonym suggestions in Vim insert mode?
Answer
<C-x><C-t>
Explanation
Vim's insert-mode completion includes a thesaurus mode triggered by <C-x><C-t>. When configured with a thesaurus file, it suggests synonyms and related words for the word before the cursor. This is useful for writing prose, documentation, or commit messages when you want to avoid repeating the same word.
How it works
- First configure a thesaurus file in your
vimrc:
set thesaurus=~/.vim/thesaurus/english.txt
- In insert mode, type a word and press
<C-x><C-t>to open the thesaurus completion menu - Use
<C-n>and<C-p>to cycle through synonym suggestions - Press
<Enter>or keep typing to accept the selected word
Example
With cursor after fast:
The process is fast|
Press <C-x><C-t> to get suggestions like:
fast
quick
rapid
swift
speedily
Tips
- Thesaurus files use the Moby Project format: the first word on each line is the keyword, followed by a tab and comma-separated synonyms
- Free thesaurus files: the Moby Thesaurus (
mthesaur.txt) is widely used and easy to find - Neovim users can use
vim.opt.thesaurus:append(path)in Lua config - You can set multiple thesaurus files separated by commas:
:set thesaurus+=~/custom.txt <C-x><C-t>respectsignorecase— it will matchFast,FAST, andfast