How do I enable spell checking in Vim?
Answer
:set spell
Explanation
The :set spell command activates Vim's built-in spell checker, which highlights misspelled words directly in your buffer. This is invaluable when writing documentation, commit messages, comments, or any prose within Vim.
How it works
:set spellenables spell checking for the current buffer- Misspelled words are highlighted (typically with a red underline or wavy line, depending on your color scheme)
- By default, Vim uses the English language dictionary
Navigating misspelled words
]s— jump to the next misspelled word[s— jump to the previous misspelled wordz=— show a list of spelling suggestions for the word under the cursorzg— add the word under the cursor to your personal dictionary (mark it as "good")zw— mark the word under the cursor as misspelled (undozg)1z=— automatically accept the first spelling suggestion
Example
You are writing a README file and type:
This is a tstrng with som misspeled words.
After running :set spell, Vim highlights tstrng, som, and misspeled. Press ]s to jump to tstrng, then press z= to see suggestions like testing, tasting, string. Select the correct one by typing its number.
Changing the spell language
To check spelling in a different language or multiple languages:
:set spelllang=en_us
:set spelllang=en_us,de
Tips
- Use
:set nospellto turn off spell checking - Use
:setlocal spellto enable spell checking only in the current buffer - Use
zgliberally to teach Vim about technical terms, project-specific words, and proper nouns so they stop being flagged - Add spell checking to specific file types in your vimrc:
autocmd FileType markdown,text,gitcommit setlocal spell
- Use
:set spellfile=~/.vim/spell/custom.utf-8.addto specify a custom dictionary file for your added words - Vim can download spell files automatically — if you set a language that is not installed, Vim will offer to download it for you