Prevent vim from clearing the clipboard on exit

8

1

If I copy text into the xterm clipboard from vim, it is cleared when I exit vim.

How do I prevent this?

Clark Gaebel

Posted 2011-06-20T01:02:51.530

Reputation: 273

Related: https://stackoverflow.com/q/6453595/4694621

– Mateusz Piotrowski – 2018-06-03T16:15:00.647

Answers

7

I recently solved this problem with this single line in .vimrc (requires utility xsel):

autocmd VimLeave * call system("echo -n $'" . escape(getreg(), "'") . "' | xsel -ib")

It stores current registry text to the clipboard buffer.

sgtpep

Posted 2011-06-20T01:02:51.530

Reputation: 256

2..or even better to use direct input redirection with system: system("xsel -ib", getreg()) – sgtpep – 2012-02-14T21:04:59.763

4

I use xclip to do so:

autocmd VimLeave * call system("xclip -o | xclip -selection c")

Gris Ge

Posted 2011-06-20T01:02:51.530

Reputation: 41

1

It’s fairly simple:

  1. Install Parcellite or glipper for Gnome, or klipper for KDE
  2. Restart your system or run it manually

See this page for more information and options.

Soli

Posted 2011-06-20T01:02:51.530

Reputation: 111

0

I don't have a good answer, and I don't have access at the moment to a system running X to experiment with, but this topic is discussed in the Vim reference manual here:

:help x11-selection

You didn't say how you copied text to the clipboard, but if you used the * register, it might help to use the + register instead.

garyjohn

Posted 2011-06-20T01:02:51.530

Reputation: 29 085

I use the + register. – Clark Gaebel – 2011-06-22T14:38:03.413

0

Try selecting while holding down shift instead. This (usually) tells your terminal emulator to directly copy text instead of sending the mouse events to Vim. Exiting Vim after doing it this way should not destroy the contents of the copy buffer, and a middle-click in another application should paste the selected text.

This will not help you with gVim. However, you note you use the + register, which means you should be accessing the clipboard, which is not destroyed on exit of the application that last "wrote" to it. This register is not pasted using middle-click with the mouse. Either use control-v (for applications that support pasting from the clipboard with that hot key) or right-click and select paste.

Heptite

Posted 2011-06-20T01:02:51.530

Reputation: 16 267