How to copy data between different instances of vim?

First you must install a clipboard-enabled version of vim. To accommodate users with non-graphical environments (eg Ubuntu Server users), vim and vim-tiny do not hook into this capability. You'll want to install GVim Install GVim, which be launched either graphically or in your terminal. GVim will replace the vim command.

You can yank the text into the 'cut buffer' from the first vim, and then paste the text into the second vim. To copy to the global cut buffer, use the + register. The " key allows you to specify which register to use when doing a yank or paste operation.

In the first vim, yank a line into the + register:

"+yy

then, to paste from the + register in the second vim:

"+p

For more information on the registers available, check out :help registers. You can also use "+p to paste text copied from any other source on your system.


Best solution that worked for me (that doesn't require me to change my keybinding habits) is here: https://stackoverflow.com/questions/9166328/how-to-copy-selected-lines-to-clipboard-in-vim

just put:

set clipboard=unnamedplus

in your .vimrc.


I like the solution of Bill, and I have created a mapping:

vmap <leader>y :w! /tmp/vitmp<CR>                                                                   
nmap <leader>p :r! cat /tmp/vitmp<CR>

the first one in visual mode copy all in /tmp/vitmp and the second one copy the content from /tmp/vitmp in the file

Tags:

Vim

Clipboard