I recently started use :imap jj and am trying to unlearn Ctrl+[.
However, imap doesn't work when paste mode is on. How do I make it work in paste mode?
When using Vim under Windows, the clipboard can be accessed with the following: In step 4, press Shift+Delete to cut or Ctrl+Insert to copy. In step 6, press Shift+Insert to paste.
IIRC when you paste into vim, it essentially thinks that you typed all those characters yourself. So if auto-indent is turned on, it will indent stuff for you, but the pasted text usually contains indentation already so the indent indeed gets "messed up". Switching to paste mode turns off stuff like auto-indent.
You simply can not have mappings work when 'paste' is enabled, since that is the whole point of Vim's paste mode.
Vim's paste mode is meant to allow you to paste stuff even in an instance of console Vim in a terminal—where Vim may not be aware you're using the mouse to paste—and you want to insert literal text form your paste buffer without triggering mappings, or auto/smart/expression indenting, etc.
I suggest you take a look at:
:help 'paste'
:help 'pastetoggle'
Add following snippet to your .vimrc to trigger paste mode automatically when pasting via the terminal:
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
From: https://coderwall.com/p/if9mda
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With