I had a ridiculous typo in a Git commit message recently, so I decided to explore spell checking in Vim. As it turns out, it’s extremely easy.
I only wanted it enabled for Git commit messages and markdown, so I added the following to my vimrc / init.vim:
" Spell-check Markdown files and Git Commit Messages
autocmd FileType markdown setlocal spell
autocmd FileType gitcommit setlocal spell
By doing this, it highlights potential misspellings in red underline. You can see a list of potential corrections by moving the cursor over the word in normal mode and pressing z=
. Or you can add the word to the dictionary by pressing zg
.
While trying this out, I also discovered that you can enable dictionary auto-completion using Vim’s normal ctrl-n
and ctrl-p
. To enable this (again, for select file types), add the following to your vimrc / init.vim:
" Enable dictionary auto-completion in Markdown files and Git Commit Messages
autocmd FileType markdown setlocal complete+=kspell
autocmd FileType gitcommit setlocal complete+=kspell
Then, while in insert mode, type part of a word and hit ctrl-n
to start cycling through potential matches and ctrl-p
to cycle through in reverse.
Here’s a quick demonstration of both spell check and dictionary auto completion: