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

VimVi

Vim Problem Overview


I use gvim in windows. How to copy text from current position to the end of line in vi and paste it in another file opened in vi. I googled it but cant find any solution for this. Appreciate any help on this. Thank you.

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

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.

Solution 3 - Vim

Add this line to your .vimrc

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

More at my vimrc.

Solution 4 - Vim

A different solution: Dp and paste it with p. In fact this first deletes to the end of line and re-pastes it at the same location. Paste it somewhere else with p.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjavalearnerView Question on Stackoverflow
Solution 1 - VimDon RebaView Answer on Stackoverflow
Solution 2 - VimkennyView Answer on Stackoverflow
Solution 3 - VimAndy RayView Answer on Stackoverflow
Solution 4 - VimDaniel PorumbelView Answer on Stackoverflow