Vim has a built-in spell checker and it’s smart and easy to use. We can enable
the spell checker with set spell
and we can set the language with
set spell spelllang=[lang]
. It is possible to set the language on local
buffer with setlocal spell spelllang=[lang]
.
If it’s enabled, it has 3 states for a word:
- Everything is good.
- I know what you mean, but that’s not how you spell it. (for example colour vs colour).
- I don’t know what it is, but I can suggest you words similar to that.
View and accept suggestions
When the cursor is on a word z=
will open a list of words ranked by
likelihood, usually the first 5 contains the desired word.
Show next error
With ]s
we can move the cursor to the next misspelled word, while [s
moves
it backwards.
Add a new word to the dictionary
If we have a word that’s correct, but vim still yelling at us, we can add the
word into our dictionary with zg
. On a clean vim, usually I just type in a lot
of acronyms and jargon, and add them all.
Mark a word as incorrect
If we know a word was misspelled, but vim things it’s still valid, we can mark a
word incorrect with zw
.
Extra / Bonus
With :abbreviate
and :read
, it’s a dream editor to write documentation. In
vim abbreviations will be replaced with it’s full form. It’s good to shorted
often used phrases, or even to autocorrect some spelling mistakes.
Autocorrect:
ab teh the
ab tehn then
Replace abbreviations used online:
ab av I have
ab ofc of course
ab bcos because
ab WW Weaveworks
Be polite:
ab rtfm read the fine manual
Poor man’s snippet toolkit:
ab Req Request
ab forin for key, value in range list {<CR>}
ab logerr if err != nil {<CR>logrus.Error(err)<CR>}