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
zgmarks 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.addor 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)zug— undo a previouszg(remove word from the good list)zuw— undo a previouszwz=— 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(oren_gb, etc.) - Navigate between misspelled words with
]s(next) and[s(previous) - For project-specific words, point
spellfileto a repo-local file::set spellfile=./.vim-spell.add - Words added with
zgare stored in plain text, so you can commitspellfileto version control to share accepted terms with teammates