vim :global Yank every line matching a pattern


The command

:g/apples/y A

will yank all lines containing the word apples into the a register, which can be pasted with "ap. Any regular expression can be used.

Note the space before the A, and the capitalization of the register letter. If a capital letter is used as the yank register, matches will be appended to that register. If a lowercase letter is used, only the last match will be placed in that register.