Created
January 25, 2012 19:21
-
-
Save erikw/1678023 to your computer and use it in GitHub Desktop.
Toggle spellang in Vim.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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