Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim move / copy line to end of file without moving cursor?

Tags:

vim

I often use :.m$ to move or :.t$ to copy current line to the end of the file. Sometimes it would be easier if the cursor won't jump to end of file or target location of the move / copy command. Is there an option for it?

like image 549
vbd Avatar asked Dec 16 '14 08:12

vbd


1 Answers

give these two mappings a try:

"move current line to the end of buffer without moving cursor
nnoremap <leader>mv ddGp``

"copy current line to the end of buffer without moving cursor
nnoremap <leader>cp YGp``

note that for the move case, the cursor position would be changed to the text of next line, since the original line of text has gone. But it sits on same line (number).

If you required the anonymous register (") to be untouched, I think we need write a function for it.

like image 129
Kent Avatar answered Oct 14 '22 13:10

Kent