using F5 to toggle spellcheck in vim 7

After having this working for a while, I thought I’d share this section from my .vimrc:

inoremap <silent> <F5> <c -O>:call SpellToggle()<cr>
map <silent> <F5> :call SpellToggle()<cr>
function SpellToggle()
    if &spell == 1
        set nospell
    else
        set spell
    endif
endfunction

4 Responses to “using F5 to toggle spellcheck in vim 7”

  1. Anonymous says:

    Thanks!

  2. Massimo says:

    Hi, is there a way to make it work in insert mode as well?

  3. kenguest says:

    hi Massimo – this works for me in insert mode too; no changes required.

  4. LJ says:

    You can use ‘:set spell!’ to toggle spelling as well.