In case someone is interested, here is the function:
"====================================================================
" myspell.vim
"
" This fuction allows switching spellchecking in two languages, and
" to have a local spell file and/or a local tags file for each
" project. The local spell files is called 'local.utf-8.add' and the
" tags file is '.tags'.
"
" Using tags:
"
" The 'tags' file is a text file that lists one tag per line, organized
" alphabetically. A tag is a keyword preceded by the '@' sign. For
" instance @novel. This tag file is used to autocomplete tags in
" reference files. Autocomplete is triggered by C-X.
"
" Note: To create a '.local.utf-8.add' file, open it in Vim, save it,
" and run: mkspell to generate the local spell file.
"
" Note: To create a 'tags' file, go to the root folder of a given
" project and issue ':maketags.sh'. This will create a 'tags' file.
" Make sure that the '.local.vimrc' in the root file for the project
" includes the line 'let g:localroot=<project's root>'
"
" Inspired by:
" http://vim.wikia.com/wiki/Toggle_spellcheck_with_function_keys
"====================================================================
if exists("loaded_myspell")
finish
endif
let loaded_myspell = 1
let g:myLangList = [ "nospell", "en_us", "es", "" ]
let g:myLangName = [ "No spelling", "US English", "Spanish", "Tags" ]
let g:myLangShort = [ "", "EN", "SP", "T" ]
function! MySpellLang()
" Check if 'g:myLang' exists for the buffer in question, and if it
" doesn't check if spell is set and adjust 'g:myLang' accordingly.
if !exists( "g:myLang")
if &spell
let g:myLang=index(g:myLangList, &spelllang)
else
let g:myLang = 0
endif
endif
" Spellfile
" g:localroot can be configured in '.local.vimrc' at the root
" level of any project. This configuration is read by the plugin
" 'vim-localrc' (which also reads any other configuration settings).
if !exists("g:localroot")
let g:localroot=expand('%:p:h')
endif
let g:localspell=fnameescape(g:localroot).'/.local.utf-8.add'
" Loop through languages
let g:myLang += 1
if g:myLang >= len(g:myLangList) | let g:myLang = 0 | endif
if g:myLang == 0
set nospell
set spellfile=
set dictionary=
elseif g:myLang == 1
set spell spelllang=en_us
" 'set' needst to be use for '~' to be resolved here
set spellfile=~/.vim/spell/en.utf-8.add
set dictionary=
elseif g:myLang == 2
set spell spelllang=es
set spellfile=~/.vim/spell/es.utf-8.add
set dictionary=
elseif g:myLang == 3
set nospell spellfile=
let b:localtag=fnameescape(g:localroot).'/.tags'
if !filereadable(b:localtag)
" Save current directory, removing new-line and escaping spaces
let b:savedir = fnameescape(substitute(system('pwd'),'\n','','g'))
" Go to the local root
:execute "cd ".fnameescape(g:localroot)
" Call the tag maker script
:execute "silent !maketags.sh ".b:localtag
" Change directory back
:execute "cd ".b:savedir
endif
exec ":set dictionary+=".b:localtag
endif
if g:myLang>0 && g:myLang<3 && filereadable(g:localspell)
exec "set spellfile+=".g:localspell
endif
echo "language: " g:myLangName[g:myLang]
endf
map <F6> :call MySpellLang()<CR>
imap <F6> <C-o>:call MySpellLang()<CR>
"================================================================ EOF
'dictionary'
option to point to a different file. Alternatively you could turn your tags into vim tags and use CTRL-X CTRL-T or write a user-defined completion function and use CTRL-X CTRL-U. Both of these would be harder to do, though.