Vim Recipes Typing Spell Checking

Spell Checking

Problem

You want Vim to highlight misspelled words and suggest alternatives.

Solution

To enable spell checking you first need to ensure that Vim knows which language you're typing in. If you execute :echo &spelllang you'll see the language code that Vim thinks applies. For instance en. To change this use :set spelllang=code. For example, I use :set spelllang=en_GB.UTF-8.

If you're spell checking in American English, you should already have the dictionary installed. Otherwise, Vim should prompt you to download it. If you're not and it doesn't, see the Getting Dictionaries sidebar of Auto-Completing Text.

To highlight spelling errors just execute :set spell. To remove the highlighting: :set nospell.

Discussion

Spelling errors are highlighted in one of four colours depending on the type of error:

You can jump to the next spelling error after the cursor ]s and jump backwards with [s. Similarly, you can use ]S and [S to only jump between words not in the dictionary (i.e. rare, and region-specific misspellings are skipped).

Once the spelling errors are highlighted, you presumably want to correct them. If you hit z= over a misspelled word you'll be presented with a list of suggested spellings. Enter the number corresponding to the correct spelling and hit <Enter>.

If a correctly spelled word is highlighted as an error, you can add it to your personal dictionary with zg. This prevents it from being marked as an error in the future.

Conversely, if an incorrectly spelled word isn't highlighted, you can add it to the bad word list with zw.