1

I know that I can paste the clipboard in by by typing ctrl-shift-v.

The problem is that this is a very counterintuitive shortcut. It requires me to move my hand in a very uncomfortable way.

I would like to paste the clipboard with something better, such as gcp.

I am trying to put a line in my vimrc file that will accomplish this, but I am getting major headaches as it seems to be impossible to do. Instead I must resort to some buffers, which i have been looking at for a while without result.

How do I place a line in the Vimrc which allows me to paste the clipboard content onto the file I'm in, upon a click of a shortcut of my choosing?

p.s. Solution was to install vim-gtk and after that i could do: :put +

john-jones
  • 235
  • 2
  • 11

2 Answers2

4

Assuming Vim has access to the clipboard, you can insert the clipboard contents (in Vim register +) via <C-R><C-R>+ (in insert mode) and via "+p in other modes.

Thus, some mappings could be:

:noremap <F2> "+p
:noremap! <F2> <C-R><C-R>+

To paste as completely new lines, you can also use

:put +
Ingo Karkat
  • 17,819
  • 1
  • 45
  • 61
3

Update: In order to access the system clipboard(s) Vim needs to be compiled with support for this. You can use the commands :echo has('clipboard') and, on Unix, :echo has('xterm_clipboard') to check for this. As it turns out, question asker did not have these features compiled in. Their ctrl-shift-v shortcut was pasting into the terminal and Vim was receiving the text as if it were typed. This existing question describes how to get the system clipboard accessible from within Vim.

The standard method of pasting from the system clipboard is via the + register, which you can access from normal mode with a command such as "+p. (Outside of X11 sytems, the * register will also work. See :help x11-selection for a discussion of the difference.)

You can therefore create your gcp mapping for normal/visual/select modes with the commands:

:nnoremap gcp "+p
:noremap gcp "+p

The following works for insert mode (see :help i_CTRL-O), but gcp isn't the best choice of trigger in insert mode, for obvious reasons, so you're probably going to want to pick something else:

:inoremap gcp <c-o>"+p

N.B. ctrl-shift-v is not a standard Vim shortcut, and as far as I'm aware, such a shortcut can only be set up outside of Vim. Is there any chance you're on Windows, you have clipboard=unnamed set, and you're actually just using mswin.vim's ctrl-v shortcut?

Rich
  • 31,891
  • 3
  • 72
  • 139