Vim Has Spell Check!?Published:
Did you know vim has a build in spell check system? The built in spell system will ignore code variable names and functions by default but it does detect spelling mistakes in your comments and doc blocks (you do write helpful comments right?).
Turn on Spell Check
For most UNIX based systems run
:set spell in visual mode to turn on spell check (
:set nospell to turn it off). In spelling mode all misspelled words will be highlighted in some way. Most build in themes will highlight misspelled. Vim will also highlight bad capitalization and alternative spellings for your set region. Changing your region is as simple as
setlocal spell spelllang=en_us (vim will show any warnings if the region you selected is not supported).
Navigate Spell check
So you have all your misspellings highlighted…how do you fix them? Type
]s to go to the next misspelled word (
[s to go back). If the word you are on is misspelled type
z= and you will be presented with a numbered list of words vim thinks you meant. Type the corresponding number and hit enter and vim will fix the word for you! Neat! (hit enter to exit the list without choosing a word)
Add and remove words from dictionary
What if vim is wrong? To add a word to your local dictionary move the cursor over the incorrectly marked word and type
zg to add it to your dictionary. If you do this by accident you can type
zug to undo. If you want vim to mark a word as misspelled you can add it to your wrong word list by typing
zuw to undo).
Like all things with vim if you want to learn more enter the help command for spell
:help spell and vim will open the spelling help docs for your perusing pleasure.