1

I want to keep my Vim spelling synchronised across machines. For that reason I put my spelling file into Dropbox by adding set spellfile=$HOME/Dropbox/vim/spell/en.utf-8.add to my .vimrc. It worked just fine for a single language.

When I've added another spelling file for Ukrainian by changing 'spellfile' value to
$HOME/Dropbox/vim/spell/en.utf-8.add,$HOME/Dropbox/vim/spell/uk.utf-8.add it gets ignored. zg (with :set spelllang=uk) adds a word to en.utf-8.add instead of uk.utf-8.add. Words are added to the correct file when doing 2zg but that's not what I want to do manually.

How can I make Vim use correct spelling file based on 'spellang' value?

I've read Vim help on 'spellfile' and it says:

Normally one file is used for all regions, but you can add the region name if you want to. However, it will then only be used when 'spellfile' is set to it, for entries in 'spelllang' only files without region name will be found.

Initialy I've thought it means regions like en_us en_gb. Do I misunderstand something?

Another even better option would be to change location /spell directory location to live outside .vim/

1

You can symlink ~/.vim/spell to ~/Dropbox/vim/spell:

$ rmdir ~/.vim/spell
$ ln -s ~/Dropbox/vim/spell ~/.vim/spell

This will work on UNIX-like systems (Linux, BSD, OSX), for Windows, you can use:

$ mklink /D "$HOME\Dropbox\vim\spell" "$HOME\_vim\spell"
  • So simple and elegant solution! Only I'd rather mkdir ~/Dropbox/vim && mv ~/.vim/spell ~/Dropbox/vim/ instead of rmdir :) – raindev Apr 26 '15 at 19:59
  • How does this solve having to do 2zg for the secondary language? – jcr Mar 10 '17 at 8:53
2

If you have multiple entries in 'spellfile', you have to supply a [count] to commands like zg to choose the correct target file.

A better approach is to make the 'spellfile' entry always correspond to 'spelllang'. So, set either

:set spelllang=en spellfile=$HOME/Dropbox/vim/spell/en.utf-8

or

:set spelllang=uk spellfile=$HOME/Dropbox/vim/spell/uk.utf-8

Because that is tedious, you can define custom commands or mappings:

:command! -bar SpellEn set spelllang=en spellfile=$HOME/Dropbox/vim/spell/en.utf-8

This would only not work if you have mixed-language documents. In that case, there's no way around defining both and using [count].

  • That's strange to me that with :set spellfile=<list of .add files in ~/.vim/spell> Vim will work differently than if I would leave 'spellfile' empty. Vim will work with exactly the same set of files but would threat them differently. Was it implemented this way intentionally with some specific use case in mind? – raindev Apr 26 '15 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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