I'm trying to write an insert mode mapping for pasting from the system clipboard. I have this:
imap <c-p> <c-o>:set paste<cr><c-r><c-r>+<c-o>:set nopaste<cr>
(Note that this is supposed to work according to this)
However when invoking the key mapping, it doesn't work, it stops short at the set paste part, so I just end up with paste mode enabled.
But if I do all those keys manually then I get what I want...so what's different when the commands are under a keymap? What am I missing to make this work?
I have also tried this:
imap <c-p> <esc>"+gP
This throws a slew of errors about gP being an unknown variable, but the same mapping in normal mode works as expected...so what's different with insert mode mappings?
vim
in a terminal all day, have no problems pasting, and don't jump through all those hoops. To paste from the + register while maintaining the original formatting, use<C-R><C-O>+
. See:help i_CTRL-R_CTRL-O
for more on this. I don't know what's wrong with your second imap--it works fine for me.