How to copy from one vim instance to another using registers

vim

How can I select the + register? I have problems following the instructions below to copy/paste text from vim to another vim:

In the vim, highlight, select + register, and yank (save) to it:
Shift-v
"+y

In the second vim, select + register, and paste from it:
"+p

I think I'm pressing the wrong keys. When it says "+y, do I simply hit the keys ", +, y in sequence? (That is, Shift+', Shift+=, y). It does not work for me.

I am using Red Hat and vim in an X11 terminal. And vim version is

$vim --version | grep xterm_clipboard
-xterm_clipboard -xterm_save

Best Answer

Vim uses the system cut-and-paste mechanism to copy text between instances. When you run vim in a terminal, it doesn't have direct access to any cut-and-paste mechanism. If vim is running in xterm or some other terminal that provides access to X selections and clipboard contents, vim can use that; however your vim binary is compiled without support for that feature.

If both vim instances are running on the same machine, you can use a temporary file to communicate:

:w ~/vim.tmp
:r ~/vim.tmp

If both vim instances are connected to the same X display (in that the DISPLAY environment variable points to the same X display, the vim programs themselves don't need to have any kind of X support), you can use the X selections via an external program such as xsel or xclip. You can omit the p or -selection primary or choose a different selection (-s/secondary or -b/clipboard). Use :w ! (note the space) to copy:

:w !xsel -ip
:w !xclip -i -selection primary

and :r! to paste:

:r !xsel -op
:r !xclip -o -selection primary
Related Question