Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
add comment

1 Answer

Paste mode is not intended for long periods of typing. It exists only to overcome longstanding limitations of Vim when running in a terminal. You should not use it for anything else than pasting text with the middle mouse button.

That's why set pastetoggle="<F12>" exists: Want to paste something? Hit <F12> to enter paste mode, paste, hit <F12> again to exit paste mode.

Alternatively, use "*p or "+p if your version of Vim supports it.

share|improve this answer
    
Thank you. I don't do any typing in Paste mode, but I do use it often enough that I want to keep it on the three-way toggle with my two other insert modes. Also, it saves me a Function key which is a big help, as I have the others assigned to other things. –  dotancohen Aug 31 '12 at 14:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.