You are not logged in.

#1 2019-09-18 12:45:57

kibartas
Member
Registered: 2019-01-29
Posts: 29

[SOLVED] Copying from vim to the same terminal doesn't work

Hi. I can't seem to be able to copy and paste from vim to the same terminal, meaning: I write something to vim, then "+Y the line I wrote. Then I close vim and try to paste the copied text to terminal but it doesn't work. The terminal I use is st and I have the shortcut alt+v enabled to paste.

It works if I copy text from a browser or from another terminal window that has vim open, but I can't do it from the same one. Any ideas on why?

I should mention that I use VIM and have gvim installed for the clipboard functionality.

The only thing I could find on the net about this was: https://stackoverflow.com/questions/511 … e-terminal which wasn't very helpful.

Last edited by kibartas (2019-09-24 14:37:18)

Offline

#2 2019-09-18 15:26:22

Alber
Member
From: Spain - España
Registered: 2011-11-11
Posts: 227

Re: [SOLVED] Copying from vim to the same terminal doesn't work

Hello.
I don't know much. And no experience with st.
Does mouse middle button work to paste?

Last edited by Alber (2019-09-18 15:28:04)


Because not all of us are native English speakers, try no to use slang or abbreviations, thank you.

Offline

#3 2019-09-18 15:29:40

Skunky
Member
Registered: 2018-01-25
Posts: 231

Re: [SOLVED] Copying from vim to the same terminal doesn't work

Does it work if you keep vim open?

Offline

#4 2019-09-18 16:22:33

Swiggles
Member
Registered: 2014-08-02
Posts: 266

Re: [SOLVED] Copying from vim to the same terminal doesn't work

I think gvim clears the buffer on exit, but you can use it like this:

"*yy
:sh
shift+insert

#When done press ctrl+d to return to vim

Offline

#5 2019-09-24 12:04:31

kibartas
Member
Registered: 2019-01-29
Posts: 29

Re: [SOLVED] Copying from vim to the same terminal doesn't work

Alber wrote:

Hello.
I don't know much. And no experience with st.
Does mouse middle button work to paste?

Sorry, for late reply. I use alt+v to paste, middle button doesn't have that functionality set to it.

Offline

#6 2019-09-24 12:05:14

kibartas
Member
Registered: 2019-01-29
Posts: 29

Re: [SOLVED] Copying from vim to the same terminal doesn't work

Skunky wrote:

Does it work if you keep vim open?

The exact problem is, I write a command to vim, then I copy it, close vim and try to paste it into shell, but it doesn't work

Offline

#7 2019-09-24 12:06:41

kibartas
Member
Registered: 2019-01-29
Posts: 29

Re: [SOLVED] Copying from vim to the same terminal doesn't work

Swiggles wrote:

I think gvim clears the buffer on exit, but you can use it like this:

"*yy
:sh
shift+insert

#When done press ctrl+d to return to vim

I guess that works. I mean, it works if I do "+yy, not with "*yy. It's still strange how I can paste it into anywhere EXCEPT the same terminal window.

Offline

#8 2019-09-24 12:17:54

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

Re: [SOLVED] Copying from vim to the same terminal doesn't work

What is "+Y supposed to do?  That's not a default binding for anything.

Which buffer is it supposed to copy to?

What buffer have you configured st to paste with alt+v?

Use `xsel` and `xsel -b` after exiting vim to check the contents of the primary and clipboard buffers - is the text you 'copied' in either of them?  Which one?


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

Offline

#9 2019-09-24 14:36:26

kibartas
Member
Registered: 2019-01-29
Posts: 29

Re: [SOLVED] Copying from vim to the same terminal doesn't work

Trilby wrote:

What is "+Y supposed to do?  That's not a default binding for anything.

Which buffer is it supposed to copy to?

What buffer have you configured st to paste with alt+v?

Use `xsel` and `xsel -b` after exiting vim to check the contents of the primary and clipboard buffers - is the text you 'copied' in either of them?  Which one?

Well, Y in VIM copies the line. "+ is the register to which it copies to and this is linked with CLIPBOARD.
From VIM Help pages:

There are three documented X selections: PRIMARY (which is expected to
represent the current visual selection - as in Vim's Visual mode), SECONDARY
(which is ill-defined) and CLIPBOARD (which is expected to be used for
cut, copy and paste operations).

Of these three, Vim uses PRIMARY when reading and writing the "* register
(hence when the X11 selections are available, Vim sets a default value for
|'clipboard'| of "autoselect"), and CLIPBOARD when reading and writing the "+
register.  Vim does not access the SECONDARY selection.

I have configured alt+v to paste from CLIPBOARD.

Okay, so I have figured something out. I think I may have misled myself and others on this one. Actually, when copying to the "+ register aka to CLIPBOARD, it gets wiped after I close vim.

When copying to "* register it lingers after I close vim. But it's pretty much useless, because it's not clipboard and I don't really know what to do with it.

xsel and xsel -b doesn't return anything.

Anyway, I have actually found this article on stackoverflow just now: https://stackoverflow.com/questions/645 … rd-on-exit

VIM clears clipboard after closing, but there is a workaround that's detailed in the page.

I'd say this is solved, thanks everybody.

Offline

#10 2019-09-24 15:15:25

Swiggles
Member
Registered: 2014-08-02
Posts: 266

Re: [SOLVED] Copying from vim to the same terminal doesn't work

autocmd VimLeave * call system("xsel -ib", getreg('+'))

In case the link ever becomes unavailable. This is actually neat. Thanks for the follow up!

Offline

Board footer

Powered by FluxBB