vim - how do I cut some lines of file-1 to file-2 in 1 step?

When I need to cut some lines from one file to another file, I always do the following steps:

• Select the lines in file-1
• :w >> file-2
• Re-select the lines
• d

This is super annoying if you need to do it for like 10 times.

So, is there anyway I can write the selection to another file and delete the selection in the same time?

Edit: maybe using gvd to reselect and delete is a faster option.

You could make it a one liner using a range:

2,3w >> b | 2,3d


And if you want to keep doing this with visual selection, you can select the lines and then use '< and '> for the range:

'<,'>w >> b | '<,'> d


• If the file you're trying to write doesn't exist you can use w! to force the command
• The | character is used to chain commands (not unlike && in bash), you can read about it at :h :bar:
                        *:bar* *:\bar*

• As a command: command! -range -complete=file_in_path -nargs=1 Wd <line1>,<line2>write >> <args> | <line1>,<line2>delete _ Jun 25 '19 at 21:11
• Thank you, this works! But there is one issue: if file b does not exist, vim will return an error (E212: Can't open file for writing). Also, 1) Can you please explain what | do in the command? 2) typing '<,'> is not faster than reselect and delete with gvd. Jun 26 '19 at 1:41
• For error, use w! >>. The bar is a command separator. Jun 26 '19 at 2:50