I use vim's spellchecking feature. Given that I work with many technical terms and LaTeX commands, I tend to add many them to my personal dictionary in ~/.vim/spell/en.utf-8.add.

I would like to share this file across multiple machines, so that when I add a word to the file on one machine, it is also added on other machines, and I don't need to add it once on each machine. I tried versioning ~/.vim/spell/en.utf-8.add in git, but this does not seem to work: vim does not pick up the new terms. I suspect that vim also needs the file en.utf-8.add.spl to be edited somehow, but as this file is binary, versioning it will probably lead to conflicts.

Does anyone here have a satisfactory solution to have vim spellcheck dictionary additions as part of their config, and synchronising them between all of their machines?

up vote 5 down vote accepted

Vim uses the spl file to do the checks, and the spl file is generated from the add file. We can speculate on whether the spl file is portable across different machines and Vim versions, but it's easier (and safer) to re-generate it as needed. Now, the spl file is re-generated automatically when you add words to your local dictionary from within Vim, but you must run mkspell to re-generate it if you edit the add file directly.

With that in mind, you can do something like this: synchronize the add file by whatever means (with git, rsync, NFS, or whatever), and add these commands to your vimrc on all machines:

for d in glob('~/.vim/spell/*.add', 1, 1)
    if filereadable(d) && (!filereadable(d . '.spl') || getftime(d) > getftime(d . '.spl'))
        exec 'mkspell! ' . fnameescape(d)
    endif
endfor

This will re-generate the spl file at Vim startup whenever the corresponding add file is newer than it.

  • Brilliant, thanks! I added silent before exec so I don't get spammed at startup by the progress info of the command (and don't get "Press ENTER or type command to continue"). – a3nm Oct 9 '15 at 15:20
  • @a3nm That's a matter of preference. As an senior sysadmin explained to me many years ago, being spammed with "ok" notifications is a sign things work fine. :) – Sato Katsura Oct 9 '15 at 18:48
  • By the way, if you are also using this setup, you probably want to automate the handling of git conflicts. I explained how to do that here: a3nm.net/blog/git_auto_conflicts.html – a3nm Mar 26 '17 at 22:16

I sync my .vim folder to my machines using Dropbox. Whenever I've made a change to my configuration, I'll throw it back onto Dropbox and pull it down on my other machines.

I have the commands set in my .bashrc file so I can save some typing. My Vim install isn't too complex, so it's pretty quick to sync when I make a change. Not sure how it'd handle an exceptionally large .vim folder.

  • 1
    Thanks for this suggestion! However, Dropbox is proprietary software, so it don't want to be using it. (It forces me to worry a lot more about its security, and it doesn't offer confidentiality guarantees of what I store in it.) – a3nm Mar 26 '17 at 22:18

Your Answer

 
discard

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.