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

How do I permanently add a word to my personal spell file so Vim stops marking it as misspelled?

Answer

zg

Explanation

When Vim's spell checker flags a technical term, proper noun, or project-specific identifier as misspelled, you can permanently silence it with zg ("mark as good"). Vim immediately updates your personal spell file on disk and stops highlighting that word as an error — no restart required.

How it works

  • zg marks the word under the cursor as a valid word in your spell file
  • Vim writes the entry to the first file listed in spellfile (defaulting to ~/.vim/spell/en.utf-8.add or equivalent)
  • The compiled binary spell file is regenerated on the fly
  • The change is permanent and takes effect instantly for the current and future sessions

Related commands:

  • zw — mark the word as wrong (add to the "bad words" list)
  • zugundo a previous zg (remove word from the good list)
  • zuw — undo a previous zw
  • z= — open the spelling correction menu to choose a suggested replacement

Example

With :set spell spelllang=en_us, Vim underlines AppConfig as misspelled:

Initialize the AppConfig handler.
              ^^^^^^^^^^
              (highlighted as error)

Place the cursor on AppConfig and press zg:

Initialize the AppConfig handler.
              (no highlight — permanently accepted)

Tips

  • Enable spell checking first: :set spell spelllang=en_us (or en_gb, etc.)
  • Navigate between misspelled words with ]s (next) and [s (previous)
  • For project-specific words, point spellfile to a repo-local file: :set spellfile=./.vim-spell.add
  • Words added with zg are stored in plain text, so you can commit spellfile to version control to share accepted terms with teammates

Next

How do I configure command-line Tab completion to show a list and complete the longest common match first?