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
You can copy/paste by using the +
register (read more: Accessing the system clipboard)
"+gyy
will 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.
I'm sure there are many ways, but I do it using marks
and registers
.
Marks
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
Registers
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.
@up exhausted the subject. I can just add that most of the combination related is with associated with system key combination find you in config for Gvim (eg. windows mapping for CTRL+C CTRL+V etc. is in mswin.vim)