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?

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 '16 at 6:52
  • Ah, okay. Then you would exchange tempname() with something more static. See my edit. – Ingo Karkat Oct 18 '16 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 '16 at 11:08

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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