Make Shift+Insert work in Insert Mode with "set paste" active

0

I have a Windows client with gvim for Windows 7.4. I want Shift+Insert to work as "Paste", so I added the following settings to ~/_vimrc:

nnoremap <S-Insert> "+gP 
inoremap <S-Insert> <Esc>"+gP<CR>i

This makes S+Insert work properly (paste the clipboard contents) in the following cases:

  • Normal mode.
  • Insert mode with :set nopaste active.

But when Shift+Insert is pressed in Insert mode with :set paste, then instead of the clipboard contents, the string <S-Insert> is inserted into the document.

I found this similar question (After ":set paste" executed "insert mode's remaps" stop working - VIM (iTerm2)) but related to iTerm2 (it's 1 year old) but I cannot believe there is no solution in Vim for this.

Thanks.

sromero

Posted 2016-07-21T06:29:11.277

Reputation: 101

1The whole point of :set paste is to not expand mappings. It would be a bug, if the mapping worked. – Christian Brabandt – 2016-07-21T08:42:32.860

Thanks for answering. It's OK if that's the expected behaviour, but ... is there any other way (no mappings) to achieve what I expect (Shift+Insert = paste contents) in paste mode? – sromero – 2016-07-21T08:56:17.693

doesn'T Shift+Insert do this by default and you don't need paste mode at all? – Christian Brabandt – 2016-07-21T09:04:44.220

When I'm in insert mode, it does not work. It just inserts the <S-Insert> string, but I want to behave like Shift+Insert in the terminal (paste clipboard contents). – sromero – 2016-07-21T12:30:45.750

1This is gvim right? You shouldn't need paste mode there at all. – Christian Brabandt – 2016-07-21T12:41:56.140

No answers