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.
Slackware Linux, Debian GNU/Linux, OmniOS, FreeBSD and NetBSD provide a Vim package that installs English spell checking files only.
OpenBSD has flavoured Vim packages that come with English spell checking files only. It also provides extra packages for specific additional languages.
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 command | Action |
---|---|
]s | jumps to the next identified misspelled word. |
[s | jumps to the previous identified misspelled word. |
zg | adds the “Good” word to the user’s dictionary. |
z= | displays a list of suggested corrections. |
:set spell | enables spell checking. |
:set nospell | disables spell checking. |
And that’s all for now!