Take the 2-minute tour ×

Is it possible to copy/paste text without using :vs? If I have two vi windows open, I can copy/paste text with a mouse. How can I do it with a keyboard?

I found two existing questions that are similar to this, but neither one answers my question.
how to copy codes in vi to clipboard
Copy and paste content from one file to another file in VI

share|improve this question
I just wrote a book on how to do this, but both links you provide answer the question just as well. –  jahroy May 29 '12 at 17:39
add comment

2 Answers

up vote 3 down vote accepted

You can copy/paste by using the + register (read more: Accessing the system clipboard)

"+gyywill yank a line, and put it into the + register. You can paste in your other window with "+p in normal mode, or Ctrl+r + while in insert mode.

If you don't wish to use split windows, there really is no other way to paste between windows apart from using the system clipboard.

share|improve this answer
You can use vim tabs as well as split windows. –  ostler.c May 30 '12 at 21:26
It should also be noted that on Linux there are two clipboards - the regular clipboard - the one you access with CTRL+C and CTRL+V - is mapped to the + register. The other clipboard stores the last selected text and can be pasted with middle-click - and in Vim it's mapped to the * register. –  Idan Arye May 31 '12 at 14:35
macvim uses buffer, so it is possible to copy/paste to textedit. Console VI, on the other hand doesn't allow copy/paste to textedit. –  Vlad Vinnikov May 31 '12 at 14:35
add comment

I'm sure there are many ways, but I do it using marks and registers.


You can place a mark anywhere in a file using m followed by the name of the mark you want to use.

You can use any letter between a and z (capital and lowercase) to name your marks.

You can go to the line that contains a mark with the ' key.

For example, mx marks a line with mark x and 'x moves the cursor to the line containing mark x.

You can go to the exact location of a mark using the backtick key: `

To yank from the current cursor location to the line containing mark x, for example, you would enter y'x


In order to use the clipboard, you need to use registers, which represent places you can store the text you yank.

Just like you can use different marks for each character, you can name the registers you yank text to.

You refer to a register by using the " key when yanking/putting.

For example "ay'x would yank the text between the cursor and the line containing x to register a.

The clipboard is represented by a special register: either * or + depending on your environment.

To yank the text between the cursor and the line containing mark x to the clipboard, enter the following: "+y'x

This says: use buffer + (the clipboard) to store the text between the cursor and the line containing mark x.

Once you do this, your text will be in the clipboard. You can use CONTROL-V to paste it into other apps.

NOTE: In some environments, the clipboard is represented by the buffer named *.

This may sound overwhelming, but once you get used to it, it's VERY powerful.

I use this hundreds of times every day.

If you're editing a file that has several key points of interest, you can mark each part of the file with different marks and quickly move your cursor between the code you need to edit.

Likewise, if you have several pieces of text that you need to repeatedly copy, you can store each one in a different register to make your pasting more efficient.

share|improve this answer
add comment

Your Answer


