I discovered something neat today. I have the following script in my .vimrc for all of my shells, as well as my local machine:
if &term =~ “xterm.*” let &t\_ti = &t\_ti . “e[?2004h” let &t\_te = “e[?2004l” . &t\_te function XTermPasteBegin(ret) set pastetoggle=<Esc>[201~ set paste return a:ret endfunction map <expr> <Esc>[200~ XTermPasteBegin(“i”) imap <expr> <Esc>[200~ XTermPasteBegin(“”) cmap <Esc>[200~ <nop> cmap <Esc>[201~ <nop> endif
This isn’t really a problem with local instances of vim, but remote instances, if the connection is terminated while the editor is active, it will leave this edit mode enabled in the terminal client on OS X, whether it’s Terminal.app or iTerm2.
This results in all pastes getting surrounded with `
The fix, quite simply, is to issue a `reset` command to the terminal, which will restore it to normal operation.
Noting this error and fix down for future reference.