vimtricks.wiki Concise Vim tricks, one at a time.

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

  1. Enable spell checking: :set spell spelllang=en_us
  2. Navigate to a misspelled word with ]s
  3. Fix it with z= (select from suggestions) or 1z= (accept the first suggestion automatically)
  4. Run :spellrepall to 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

  • :spellrepall only works after a z= 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

Next

How do I open just enough folds to see the current line without expanding everything?