back to Today I Learned page

Spell checker on Vim

posted at 08-07-2020

As I've writing some TIL posts lately, and I'm doing that using VIM as my main editor for it.

Sometimes I get a little bit worried about typos / wrong spelling as I'm not a native English speaker sometimes I do some silly errors (also on grammar, but that's another post for here hehe)

Vim already have a spell checker that we can set the language like that:

set spelllang=en

And enable it with set spell, if we want to have this enabled every time that we open VIM, we need to add the "set spell" on our .vimrc or .config/nvim/init.vim for neo Vim

As now we have it enabled, we should be able to use it, so here are some commands that I've been using:

Command What does it do
z= It'll open another page with a numbered list of alternatives to that wrong word, you can choose one number of this list and press enter, it'll change the word for the one chosen
]s It moves to the next misspelled word after the cursor
[s It moves to the misspelled word before the cursor
zg Adds the word under the cursor to the dictionary as a "correct word", so it'll not warn next time that you have that word
zw Like zg but adds the word to the dictionary as a "wrong word"
zug/zuw Undo what zg and zw did

Adding spell check per file type

If you want to enable the spell checker automatically based on the type of the file you can add the code below on your .vimrc or .config/nvim/init.vim for neo Vim.

autocmd BufRead,BufNewFile *.md setlocal spell

This will enable the spell checker only for markdown files, so you won't get errors on some code stuff that it's not really wrong.


If you want to take a deeper look on the spell checker, take a look on the documentation here http://vimdoc.sourceforge.net/htmldoc/spell.html

Hope it helped someone, if you have suggestions or if I did something wrong here, just ping me on Twitter