Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

How do I prevent this?

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
..or even better to use direct input redirection with system: system("xsel -ib", getreg()) – sgtpep Feb 14 '12 at 21:04

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.

share|improve this answer

I use xclip to do so:

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

share|improve this answer

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.

share|improve this answer
I use the + register. – Clark Gaebel Jun 22 '11 at 14:38

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .