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

How do I configure a custom word list file for Vim spell checking so I can persist accepted words?

Answer

:set spellfile={path}

Explanation

By default, when you use zg to add a word to Vim's spell-check dictionary, it is saved in a file in your Vim data directory. The 'spellfile' option lets you point that file at a location you control—such as a path inside your dotfiles repository—so that your personal dictionary is portable and version-controllable.

How it works

  • :set spellfile=~/.config/nvim/spell/en.utf-8.add — words added with zg are written here
  • Multiple files can be specified as a comma-separated list; zg always writes to the first one
  • The file is a plain-text list that Vim automatically compiles to a .spl binary on load
  • Combine with :set spell spelllang=en_us to activate spell checking

Example

Add to your vimrc or init.lua:

set spell spelllang=en_us
set spellfile=~/.config/nvim/spell/en.utf-8.add

Now every word you accept with zg is written to that file. Commit the file to your dotfiles repo and your custom dictionary follows you everywhere.

Tips

  • Use zg to mark a word as good, zw to mark it as wrong, and zug to undo an addition
  • If the compiled .spl file is missing or stale, Vim will regenerate it automatically
  • You can ship a pre-filled wordlist in a plugin or dotfiles repo and point spellfile at it

Next

How do I get just the filename without its path or extension to use in a command?