Reputation: 10380
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?
Upvotes: 3
Views: 749
Reputation: 270599
You can define a mapping which marks the current location, pastes at the end of the buffer using :$put
then returns to the original cursor location using the mark.
This works because :put
allows a line number prefix (the last line being representable as $
). From :help put
:
:[line]pu[t] [x] Put the text [from register x]
This would map it to <leader>
p:
:nnoremap <leader>p :mark '<cr>:$put<cr>`'
It sets the '
mark at the cursor, pastes at the end, then returns to the '
mark with `
Upvotes: 2
Reputation: 84343
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.
Upvotes: 4
Reputation: 20763
Depends on how you mean "without moving the cursor".
This will paste at the bottom of the current file and then allow you to continue where you cut the lines from.
If you dont like the split view, you can use the ctrl+o to jump back after G
Upvotes: 1
Reputation: 45087
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.
Upvotes: 2