Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paste to end of the file in VIM without moving cursor

Tags:

vim

In a text document, I'm [visually or otherwise] selecting several lines, cutting them with d... I'd like to paste these lines to the end of the file without moving the cursor. Is there a relatively simple way to do this?

like image 743
iamnotsam Avatar asked Dec 15 '25 07:12

iamnotsam


2 Answers

Use the Implicit Mark from Last Jump

You can use the implicit mark (e.g. ') to return your cursor to the location it occupied just before the last jump. For example:

Gp''

This will (G)o to the end of the file, (p)aste the contents after the last line, and then return to your position at the time you typed G.

like image 195
Todd A. Jacobs Avatar answered Dec 16 '25 19:12

Todd A. Jacobs


There are a few ways:

Marks

Set a mark, do your paste, then jump back to the mark

m':$pu<cr>``

Visual mode

Visually select your lines, copy them, append, and then restore visual selection (optionally delete)

y:$pu<cr>gv

Append to the file

Visually select your lines, use :w to append to the file, and then reload the file. (Note: will move the cursor to the start of the visually selected lines)

:w >><cr>:e!

Create your own command/mapping

You can create your own command and/or mapping that will use winsaveview() and winrestview() to append then restore the cursor.

like image 30
Peter Rincker Avatar answered Dec 16 '25 20:12

Peter Rincker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!