Skip to content

Instantly share code, notes, and snippets.

@erikw
Created January 25, 2012 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikw/1678023 to your computer and use it in GitHub Desktop.
Save erikw/1678023 to your computer and use it in GitHub Desktop.
Toggle spellang in Vim.
" Toggle spell with a language. {{{
function! ToggleSpell(lang)
if !exists("b:old_spelllang")
let b:old_spelllang = &spelllang
let b:old_spellfile = &spellfile
let b:old_dictionary = &dictionary
endif
let l:newMode = ""
if !&l:spell || a:lang != &l:spelllang
setlocal spell
let l:newMode = "spell"
execute "setlocal spelllang=" . a:lang
execute "setlocal spellfile=" . "~/.vim/spell/" . matchstr(a:lang, "[a-zA-Z][a-zA-Z]") . "." . &encoding . ".add"
execute "setlocal dictionary=" . "~/.vim/spell/" . a:lang . "." . &encoding . ".dic"
let l:newMode .= ", " . a:lang
else
setlocal nospell
let l:newMode = "nospell"
execute "setlocal spelllang=" . b:old_spelllang
execute "setlocal spellfile=" . b:old_spellfile
execute "setlocal dictionary=" . b:old_dictionary
endif
return l:newMode
endfunction
" }}}
nmap <silent> <F7> :echo ToggleSpell("en_us")<CR> " Toggle English spell.
nmap <silent> <F8> :echo ToggleSpell("sv")<CR> " Toggle Swedish spell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment