Vim Spell-Checking
Spell check your work
Since version 7, Vim has the ability to spell check documents on the fly. We can enable this functionality with the following command:
:set spell
Furthermore, we can also specify a regional variant of a language:
:set spelllang=en_us
The default spelllang=en
will allow a word whose spelling is acceptable in any English-speaking region.
See it in action
In the following screenshot, the underlined word is considered a misspelling.
In Normal mode, we can jump backward and forward between misspelled words using ]s
and ]s
commands, respectively. Then, issuing the z=
command, we instruct Vim to suggest a list of correctly spelled words for the word under/after the cursor. The prompt at the bottom of the screen advises us to insert the index of the word we want to use in place of the misspelled word.
Spell check for file type
Instead of manually turn on the spell checker each time we need it, we can turn it on based on the file’s extension. My preferred way of accomplish that is creating a file whose name is <filetype>.vim
under ~/.vim/ftplugin
with setlocal spell
in its content. You can take a look at my dotfiles, which contains examples for gitcommit
and markdown
files.
Adding words to the spell file
In Normal model, we can add any word to the spellfile
by cursoring over the desired word and issuing the command zg
.