Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

4 Answers 4

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
1  
..or even better to use direct input redirection with system: system("xsel -ib", getreg()) –  sgtpep Feb 14 '12 at 21:04
add comment

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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