How do I apply the last spelling correction to all other identical misspellings in the file?
Answer
:spellrepall
Explanation
After correcting a misspelled word with z= (or 1z= for the first suggestion), run :spellrepall to apply that same correction to every other occurrence of the identical misspelling in the current buffer. This saves you from manually jumping to each ]s match and repeating the fix.
How it works
- Enable spell checking:
:set spell spelllang=en_us - Navigate to a misspelled word with
]s - Fix it with
z=(select from suggestions) or1z=(accept the first suggestion automatically) - Run
:spellrepallto replace every remaining instance of the original misspelling with the same corrected word
:spellrepall uses the original (wrong) word and the replacement you chose, and performs a case-sensitive replacement throughout the buffer.
Example
You typed "teh" three times across a document. Position your cursor on one instance, run 1z= to accept "the", then:
:spellrepall
All remaining instances of "teh" are replaced with "the".
Tips
:spellrepallonly works after az=correction — it has no effect if you manually fixed the word or used a substitution- The replacement is global and case-sensitive — if you also have "Teh" in the file, it will not be changed by the replacement of "teh"
- Combine with
1z=(accept first spelling suggestion without the interactive menu) for a fast two-step fix:1z=then:spellrepall - You can undo all replacements at once with a single
u