In Vim, is there a way to move the selected text into <current_file>.bak
, appending or prepending?
If possible, the backup file should not be displayed.
I envision the workflow to be:
:sbak
<current_file>.bak
You can do it in three steps:
:'<,'>w! >>file.bak
to save selected lines to file.bak
(append)You can write a user-defined command Sbak
if you like:
com! -nargs=1 -range Sbak call MoveSelectedLinesToFile(<f-args>)
fun! MoveSelectedLinesToFile(filename)
exec "'<,'>w! >>" . a:filename
norm gvd
endfunc