I have a file whose content could be like the following:


I want to delete from the file all the lines matching the pattern ^foo and put them altogether somewhere else, possibly in a different file, using the p command.

I've tried using the command :g/^foo/"Ad supposing each deleted line would be appended to the register a. However the command doesn't delete anything nor appends anything to the register a.

What's wrong with the command I used? Store/append to register is not supposed to work inside a global command?

There are other commands I can use to achieve what I want?


You can to use the :normal command along with your usage of :global.

:g/^foo/norm "Add

Or you can use :delete ex command:

:g/^foo/d A

For more help see:

:h :d
:h :norm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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