0

I want to use <S-Insert> to paste the content of clipboard in vim irrespective me being in normal or insert mode

I am using [Fedora 23, Gnome terminal 3.18.3, vim 7.4 +xterm_clipboard]


The usual problem I have is:

  1. I go on the web and Ctrl-C on multiple lines
  2. Back to vim in Insert or Normal mode I want to paste WITHOUT indentation modification

And I get a paste with a messed up indentation but only when the file being copied to as a filetype like r/python (I guess because an indent is defined)


What I have found

I found this post (amongst others) but that's not working.

How I can make it work

When I use the paste mode it works For example if I do

  1. I go on the web and Ctrl-C on multiple lines
  2. In vim :set paste
  3. I do <S-Insert>

Then it works irrespective of mode OR filetype and I can :set nopaste

Another way is to paste from clipboard "+p which works (without messing with paste mode)

Leads ??

Thing is I am not even sure this is vim related, I think I cannot map <S-Insert> as if I do

nnoremap <S-Insert> <NOP>
inoremap <S-Insert> <NOP>
vnoremap <S-Insert> <NOP>

And start new terminal then vim and try <S-Insert> it still copies

Community
  • 1
  • 1
statquant
  • 13,672
  • 21
  • 91
  • 162

1 Answers1

0

I get a paste with a messed up indentation

This is because vim assumes the copied text as a stream of characters typed in to it.

If you can use system clipboard in vim, use these mappings

:map <silent> <S-Insert> "+p
:imap <silent> <S-Insert> <Esc>"+pa

You can find if vim has clipboard support using

vim --version

If you see "+xterm_clipboard", you are good to go. Use it with

set clipboard=unnamed  " or
set clipboard=unnamedplus

If using system keyboard is out of the picture, my suggestion would be to write a function that takes you to paste mode with set paste, pastes the copied text, takes you back to normal mode with set nopaste

sudo bangbang
  • 27,127
  • 11
  • 75
  • 77