I can add a word to the local dictionary or spellfile with zg.

I can use zG to add a word to the internal spellfile, but this still affects all loaded files.

How can I add spelling exceptions on a per-file or per-buffer basis, and have it still work when re-opening the file?

Is there some .viminfo magic for this?

1 Answer 1


There's nothing built-in; I guess the reasoning is that spelling (at least for a certain language) is inherently global. Any differences should be reflected in the language / dialect chosen.

You can implement such buffer-local spelling exception yourself: Get a temp file via tempname(), prepend it to 'spellfile', and then zg / 1zg will place the exception there. This would be local to a single Vim session (like zG).

If you would like persistent buffer-local spelling, instead of tempname(), either put the spell file next to the file (bufname('') . '.spl'), or place then all into a dedicated spell directory, encoding the original file path in a way that :mkview does: replace the path separator with =+ and = with ==. So, ~/foo/bar.txt would get a spellfile of /path/to/spelldir/~=+foo=+bar.txt.spl

  • Thanks - sorry to move the goal-posts, but I intended to have the ignored words persist across sessions. Any ideas?
    – Tom Hale
    Oct 18, 2016 at 6:52
  • Ah, okay. Then you would exchange tempname() with something more static. See my edit. Oct 18, 2016 at 8:48
  • Thanks - I get your logic, but I don't know how to implement your dedicated spell directory solution. How do I do this replacement?
    – Tom Hale
    Oct 18, 2016 at 11:08
  • At least in gvim there is a way to do temporary (sessions-based) spell ignores with zG (for anyone reading this wanted that like I did): superuser.com/a/133228/1023666 Sep 12, 2020 at 13:31
  • Oh, sorry - just noticed that was in the original post (too often, I skip to the answers)! Sep 12, 2020 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.