I want to delete say last 10 lines and move it to another file.
What I currently do is:
:'<,'>w
to other file,Is there any more efficient way I can do this?
You can remove one step by doing this:
:!> newfile.txt
This will use an external command to write the lines to the given filename, and simultaneously delete them because nothing was output from the command.
If you want to append to a file instead of overwriting it, then use >>
instead of >
.
You can use ex
commands instead. e.g.
:1,10w file.name
Write the first ten lines
:$-9,$w file.name
Write the last ten lines (the dollar sign denotes last line)
.vimrc
you can use the command :MoveTo file.name
function! MoveLastLines(f)
exe '$-9,$w ' . a:f "write last ten lines to the passed filename
$-9,$d "delete last ten lines
endfunction
command! -nargs=1 -range MoveTo :call MoveLastLines(<f-args>)
GV9k:w file.name gvd
) are the most efficient in my opinion.
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