I've turned on spellcheck with
:set spell spelllang=en_us. Now there's a bunch of words highlighted in red, and I just want to correct them all to their closest matches.
How can I correct all misspelled words in the entire file?
Here's something I didn't know until a little while ago: Macros can be recursive! That is, you can call a macro from within the same macro.
So, here's the command:
gg Move to the beginning of the file qq Start recording the "q" macro ]s Find the next misspelled word 1z= Correct its spelling @q Call the "q" macro (we're still recording!) q Finish recording @q Call the macro for the first time
Since there's a
@q at the end of the macro, it repeatedly calls itself until it reaches EOF. Therefore, it'll correct all the misspelled words in the entire document.
Make sure the
q macro is empty before running this, though (if not, you can clear it with