Vim has a terrific paste mode, in which abbreviations and mappings are ignored. Frustratingly, even keys that do not map to pastable ASCII characters, such as the function keys, are pasted literally. For instance the key F2 is pasted as <F2>. Is there anyway around this?
Note that pastetoggle can in fact be mapped to a function key to easily leave paste mode, however the function that I am writing changes other values when entering or leaving paste mode (such as enabling or disabling line numbers and other things). Therefore I would really like to find a workaround.
For reference, here is the current version of the function (that gets stuck in paste mode):
iab if if<Space>(<Space>{{<Esc>kA<Left><Left><Left><Left><C-R>=Eatchar('\s')<CR>
" Triple-toggle Insert Modes: coding, prose, and paste
let g:insertModeGlobal=1
function! Te()
if g:insertModeGlobal==3
" Was in paste insert mode, go to coding insert mode
set nu
set nopaste
let g:insertModeGlobal=4
endif
if g:insertModeGlobal==2
" Was in prose insert mode, go to paste insert mode
set nolinebreak
nnoremap j j
nnoremap k k
nnoremap gj gj
nnoremap gk gk
set relativenumber
execute ":Signs"
iab if if<Space>(<Space>{{<Esc>kA<Left><Left><Left><Left><C-R>=Eatchar('\s')<CR>
set nonu
set paste
let g:insertModeGlobal=3
endif
if g:insertModeGlobal==1
" Was in coding insert mode, go to prose insert mode
set linebreak
nnoremap j gj
nnoremap k gk
nnoremap gj j
nnoremap gk k
set number
execute ":DisableSigns"
iab if if
let g:insertModeGlobal=2
endif
if g:insertModeGlobal==4
let g:insertModeGlobal=1
endif
endfunction