Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

  1. I do not want to exit the first vim and reopen the second vim.

  2. I do not want to use separate window (with :sp).

share|improve this question
up vote 25 down vote accepted

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:


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.

share|improve this answer
For whatever it's worth, if you install GVim (the package might be called something like vim-gnome), the menu entries will very often give you the key shortcuts they will invoke. – zpletan Sep 6 '11 at 16:42
I don't want to install Gvim. How do I do this in vim? – trusktr Mar 22 '13 at 22:32
@trusktr actually this works in vim too. In this Q&A it says you need at least vim 7.3.74 (which means Ubuntu 11.10 or later). – lumbric Mar 28 '13 at 13:43

Best solution that worked for me (that doesn't require me to change my keybinding habits) is here:

just put:

set clipboard=unnamedplus

in your .vimrc.

share|improve this answer

I move around between various Unix-family machines and have found the following sequence always works for me:

In source vi session:

  1. Use 'ESC m a' to mark first line
  2. Use 'ESC m b' to mark last line
  3. Use ':'a,'b w! xfer' to write out range to a scratch file

In destination session:

  1. Move cursor to insertion line
  2. Use 'ESC :r xfer' to read in text

I know it's not pretty but it always works for me!

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Its actually quite simple: install a version of vim that supports clipboard. if your vim does not, get any one of the following:

sudo apt-get install vim-athena
sudo apt-get install vim-gnome
sudo apt-get install vim-gtk

Once installed, just run vim. You can also verify that clipboard is enabled by running:

 vim --version|grep clipboard

you should see +xterm_clipboard.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.