I can use the powerful :g command to delete lines that contain a certain pattern like this:

:g/^\va pattern/d

I thought I should paste the deleted content to a new place but I cannot find all those lines that have been removed by checking the registers:


The " register only remembered the one line of them which I thought would only be the last line deleted.

Can I gather all the deleted lines in one register and use them elsewhere?

2 Answers 2


Use a Dedicated Register to Which You Append

Note delete overwrites the unnamed register "" for each match. Therefore, only the last line matching the pattern is still available in "". Also the numbered registers "0-"9 are not helpful because there are only 10 of them. However, you can append each line to one of the named registers "a-"z:

:h quote_alpha:

  1. Named registers "a to "z or "A to "Z *quote_alpha* *quotea*
    Vim fills these registers only when you say so. Specify them as lowercase letters to replace their previous contents or as uppercase letters to append to their previous contents.

The steps would be

  1. Clear target register by qaq (here illustrated for "a)
  2. Find lines matching a pattern, append line to register "a when deleting the line (use capitalized letter for appending instead of overwriting)

    :g/^\va pattern/d A
  3. Paste at new location with "ap



Adding to Hotschke's answer above, once all the lines of interest are in a register ("a" in this example), here's how to write the contents to a file:

:new filename | $put a | x

Write register contents to file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.