Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy from current position to the end of line in vi

Tags:

vim

vi

I use gvim in windows. How do I copy text from the current position to the end of the line in vi and paste it in another file opened in vi?

like image 503
javalearner Avatar asked Oct 14 '11 07:10

javalearner


People also ask

How do I navigate to the end of a line in vi?

Short answer: When in vi/vim command mode, use the "$" character to move to the end of the current line.

How do I copy from beginning to end?

Place your cursor at the beginning of the page you want to copy. Click and drag the cursor to the bottom of the page you want to copy. Press Ctrl + C on your keyboard.

How do you copy the current line of text in the vi editor?

Press the ESC key to be sure you are in vi Command mode. Place the cursor on the line you wish to copy. Type yy to copy the line.


3 Answers

The normal-mode command to move to the end of the line is $.

You can copy to the end of the line with y$ and paste with p.

To copy/paste between different instances, you can use the system clipboard by selecting the * register, so the commands become "*y$ for copying and "*p for pasting.

$ move-to-linebreak

$

y$ yank-to-linebreak

y,$

"*y$ select clipboard-register yank-to-linebreak

",*,y,$

"*p select clipboard-register paste

",*,p

Check :h registers for more information.

like image 103
Don Reba Avatar answered Oct 02 '22 14:10

Don Reba


If you don't want to include the line break with the yank, you can use yg_. (Or in your case, "*yg_)

Basically, just recognize there's a difference between $ and g_ movement-wise. It's helped me on numerous occasions.

like image 57
kenny Avatar answered Oct 02 '22 14:10

kenny


Add this line to your .vimrc

" Make Y yank till end of line
nnoremap Y y$

More at my vimrc.

like image 11
Andy Ray Avatar answered Oct 02 '22 16:10

Andy Ray