You are not logged in.

#1 2018-12-13 12:39:45

huzo11
Member
Registered: 2018-10-31
Posts: 60

Copying/Pasting from clipboard in vim

Hello all, 

I was wondering how I can copy things outside vim and paste it into vim. I have looked it on the internet and some people have suggested using +y/+P or *y/*P. But neither of them work. Any ideas?

Thanks!


Be nice and live for others.
https://prismatically.blog

Offline

#2 2018-12-13 12:46:30

Piri
Member
Registered: 2018-06-02
Posts: 70

Re: Copying/Pasting from clipboard in vim

This is how I usually do it:

1. Copy your text (e.g. select text in browser and do CTRL+C)
2. Go to vim and enter INSERT mode
3. Use the paste feature of your terminal emulator (usually CTRL+SHIFT+V or CTRL+ALT+V)

Offline

#3 2018-12-13 13:12:03

huzo11
Member
Registered: 2018-10-31
Posts: 60

Re: Copying/Pasting from clipboard in vim

Hello and thanks for the answer. However, the terminal that I have is vim-based only. So those commands do not work sad


Be nice and live for others.
https://prismatically.blog

Offline

#4 2018-12-13 13:27:21

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,252

Re: Copying/Pasting from clipboard in vim

Which version of vim is installed? Afaik you need to install gvim to have relevant support compiled in (even if you just use the command line vim)

Offline

#5 2018-12-13 13:40:43

huzo11
Member
Registered: 2018-10-31
Posts: 60

Re: Copying/Pasting from clipboard in vim

V1del wrote:

Which version of vim is installed? Afaik you need to install gvim to have relevant support compiled in (even if you just use the command line vim)

I use vim v8.1.570. Does gvim override vim or is it like another extension of vi? Also it is pretty surprising that vim does not have such a simple option.


Be nice and live for others.
https://prismatically.blog

Offline

#6 2018-12-13 14:15:16

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 23,252

Re: Copying/Pasting from clipboard in vim

gvim is vim (you can still call it with vim) but with X11 support compiled in, it will for all intents and purposes replace the standard vim package. vim isn't compiled with X11 support and hence has no ability to access the clipboard.

Last edited by V1del (2018-12-13 14:15:51)

Offline

#7 2018-12-13 14:17:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Copying/Pasting from clipboard in vim

Use xsel in keybindings.  For example, I have this in my vimrc to use the 'insert' key to paste the content of the primary selection:

noremap <silent> <Insert> :set noautoindent<CR>:r !xsel<CR>:set autoindent<CR>

I don't really use the clipboard selection for anything, but for pasting into vim from there you could just add the -b flag to xsel in that binding.

For copying from vim to elsewhere, I rely on the terminal (st in my case) or tmux for that as I can use the mouse to select text and st puts it in the primary selection, or I can use tmux's copy mode and my tmux.conf is set up to sync the copy buffer to the primary selection.  It would be pretty easy also to have vim pass the content of a visual block to a selection via xsel if you wanted that.

Vim can do any of this, but it does none of this out of the box.  You need to decide what you want it to do, then put the relevant commands/bindings in your vimrc.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2018-12-13 14:33:03

seth
Member
Registered: 2012-09-03
Posts: 58,779

Re: Copying/Pasting from clipboard in vim

What is "the terminal that I have"?

Offline

#9 2018-12-13 14:53:39

huzo11
Member
Registered: 2018-10-31
Posts: 60

Re: Copying/Pasting from clipboard in vim

Thanks for the feedback guys. Install gvim did the job. However, I faced the same issue in the vim-based terminal. And since it was a custom modified terminal, when I checked the terminal's repository, it actually had a different keybinding. All is well now.

seth wrote:

What is "the terminal that I have"?

If you are still curios, this is the terminal.


Be nice and live for others.
https://prismatically.blog

Offline

#10 2018-12-13 15:58:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Copying/Pasting from clipboard in vim

That's not "vim based", that's a st fork with a lot of (bloated) options added including Ctrl-C and Ctrl-V copying and pasting.  So just use that.

Last edited by Trilby (2018-12-13 15:58:53)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#11 2018-12-14 01:33:11

huzo11
Member
Registered: 2018-10-31
Posts: 60

Re: Copying/Pasting from clipboard in vim

Trilby wrote:

That's not "vim based", that's a st fork with a lot of (bloated) options added including Ctrl-C and Ctrl-V copying and pasting.  So just use that.

Pardon my ignorance


Be nice and live for others.
https://prismatically.blog

Offline

#12 2018-12-14 16:22:59

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Copying/Pasting from clipboard in vim

I take a slightly different approach...

I use the program "autocutsel" and put it in my "~/.xinitrc" file:

autocutsel -selection PRIMARY -fork

This will sync all "copy" buffers on my computers. That means I can either highlight text or Ctrl-C text and then paste it anywhere (including in Vim) with a middle mouse click. smile

Offline

Board footer

Powered by FluxBB