Prevent vim from clearing the clipboard on exit

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

How do I prevent this?


Solution 1:

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.

Solution 2:

I use xclip to do so:

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