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?
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.
There are a few ways:
Set a mark, do your paste, then jump back to the mark
m':$pu<cr>``
Visually select your lines, copy them, append, and then restore visual selection (optionally delete)
y:$pu<cr>gv
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!
You can create your own command and/or mapping that will use winsaveview() and winrestview() to append then restore the cursor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With