Vim copy-paste across terminals
Probably the simplest thing for you to try is to put set clipboard=unnamed
in your .vimrc
and restart your vim sessions.
This lets you run yank
(e.g. yy
) in one window, and put
(e.g. p
) in another window will just work, because all vim sessions will be sharing the same X selection buffer.
On the downside, your yank buffer will be overwritten as soon as you select some text in any other window of any application.
On the upside, it also means anything you yank in vim can now be pasted into any application by middle clicking.
If you don't like that way, you can type "+
or "*
before your yank and put commands, e.g. "+yy
to yank a line.
The +
forms interact with the clipboard ("+y
is like Ctrl+C, "+p
is like Ctrl+V).
The *
forms interact with the selection buffer ("*y
is like left click and drag, "*p
is like middle click).
See Making GUI Selections, X11 selection support, and the clipboard and mouse options for details.
The accepted solution won't work in a headless set-up (no X11). A solution which works in any vim environment is to write your selection into a temporary file :w! /tmp/temp_file
then pasting from that file in the other vim instance :r! cat /tmp/temp_file
I have these two commands mapped as <leader>y
and <leader>p
in .vimrc
:
vmap <leader>y :w! /tmp/vitmp<CR>
nmap <leader>p :r! cat /tmp/vitmp<CR>
Source