Spell checking in Vim

       339 words, 2 minutes

Believe it or not, I do all my editing stuff with Vim. This includes writing emails and editing this blog content. One thing I was missing, compared to using Thunderbird or LibreOffice, is the spell checking feature. Until I took 10 minutes to read the Vim documentation .

Prerequisites

You obviously need Vim.

You also need the Vim spell checking files. The way to get them depends on the system you’re using.

Depending on your case, either install an extra spell package (for example pkg_add vim-spell-fr) or let Vim download it in your $HOME/.vim/spell the first time you’ll activate spell checking; see “setlocal spell spelllang” in the next section.

Using spell checking

Read the Vim help section for a full overview of the spell checking feature. It can be displayed using :help spell. Note that Vim only checks words for spelling, there is no grammar check.

To enable and configure the spell checking, run one of such commands from within Vim:

:setlocal spell spelllang=fr
:setlocal spell spelllang=en_gb

To configure spell checking automatically depending on file content, it is possible to add such settings in your ~/.vimrc.

au FileType markdown set spell spelllang=en_gb
au FileType mail     set spell spelllang=fr
au FileType sh       set spell spelllang=en

If you don’t have the spell checking file on your system, Vim will offer you to download and install it automatically.

Once enabled, all discovered errors are highlighted in red.

Here’s the list of commands I regularly use to manage spell checking and correction:

Vim commandAction
]sjumps to the next identified misspelled word.
[sjumps to the previous identified misspelled word.
zgadds the “Good” word to the user’s dictionary.
z=displays a list of suggested corrections.
:set spellenables spell checking.
:set nospelldisables spell checking.

And that’s all for now!