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 +

8
  • in which mode do you need?
    – Sundeep
    Oct 21, 2016 at 10:44
  • for normal mode.
    – john-jones
    Oct 21, 2016 at 13:19
  • so try nnoremap gcp "+p
    – Sundeep
    Oct 21, 2016 at 13:22
  • I go to the url of the browser, highlight it, copy it by doing ctrl-c. Then i go into vim and would like to paste it there via shortcut, so i try doing "+p in normal mode and all i get printed is "
    – john-jones
    Oct 21, 2016 at 13:23
  • 1
    check the section No +clipboard?
    – Sundeep
    Oct 21, 2016 at 13:31

2 Answers 2

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?

9
  • Im on linux. I go to the url of the browser, highlight it, copy it by doing ctrl-c. Then i go into vim and would like to paste it there via shortcut, so i try doing "+p in normal mode and all i get printed is "
    – john-jones
    Oct 21, 2016 at 13:21
  • @HermannIngjaldsson Terminal Vim or GUI Vim? What is the output of :echo has('clipboard')?
    – Rich
    Oct 21, 2016 at 13:30
  • terminal vim. the output of the echo is 0.
    – john-jones
    Oct 21, 2016 at 13:31
  • @HermannIngjaldsson What about :echo has('xterm_clipboard')
    – Rich
    Oct 21, 2016 at 13:33
  • 1
    @HermannIngjaldsson If that is the case, your version of Vim does not appear to be compiled with clipboard support. I'm not sure how your ctrl-shift-v command is working from normal mode.
    – Rich
    Oct 21, 2016 at 13:36
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 +
4
  • 1
    Shouldn't the second mapping be inoremap?
    – statox
    Oct 21, 2016 at 10:40
  • 2
    @statox: :map! combines :imap and :cmap; this might be useful in the command-line as well. See :help map-modes. Oct 21, 2016 at 11:27
  • Oh I didn't know that, thanks for the clarification!
    – statox
    Oct 21, 2016 at 11:29
  • Hmm. Shouldn't the first one nnoremap, though?
    – Rich
    Oct 21, 2016 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.