If I use the first vim to copy a line (with yy
), how do I paste to another terminal's vim (with p
)? Is there any command or settings can do it? Can I copy and paste into the global system clipboard?
I know the following ways are possible, but I want a simpler one:
I do not want to exit the first vim and reopen the second vim.
I do not want to use separate window (with
:sp
).
First you must install a clipboard-enabled version of vim. To accommodate users with non-graphical environments (eg Ubuntu Server users),
vim
andvim-tiny
do not hook into this capability. You'll want to install GVim , which be launched either graphically or in your terminal. GVim will replace thevim
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:then, to paste from the
+
register in the second vim: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:
in your
.vimrc
.I like the solution of Bill, and I have created a mapping:
the first one in visual mode copy all in /tmp/vitmp and the second one copy the content from /tmp/vitmp in the file
I move around between various Unix-family machines and have found the following sequence always works for me:
In source vi session:
ESC m a
to mark first lineESC m b
to mark last line:'a,'b w! xfer
to write out range to a scratch fileIn destination session:
ESC :r xfer
to read in textI know it's not pretty but it always works for me!
Its actually quite simple: install a version of
vim
that supports clipboard. if yourvim
does not, get any one of the following:Once installed, just run
vim
. You can also verify that clipboard is enabled by running:you should see
+xterm_clipboard
.You will probably all hate this answer. I used to work in vi back in the 80's on a variety of Unix computers and have had the recent occasion to play around in Linux.
My solution to cut and paste is using Putty running on Windows to access my Linux box.
Putty lets you copy any txt in it's window by simply highlighting it. you can then go to another Putty window/session and right-click to paste.
couldn't be easier. and now there's vim. too bad that wasn't around back in my day, it would have helped me fend of the emacs mafia.
It's not exactly using yy, but if you select the text you want to copy with mouse (sometimes you may need to use Shift-[drag]), switch to the other terminal window and do a [middle click] or Shift-[middle click] there, the text will be inserted at your current insertion point.
This works for most command-line and GUI programs, not only for vim.