Search code examples
vimvi

How to copy from current position to the end of line in 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?


Solution

  • 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.