You can use:
:let @a='' " clear register a. A faster alternative would be "qaq" in normal mode (thanks ZyX) :g/pattern/y A " yank all lines with pattern into register a, but in append mode (hence a capital letter) :buffer other_file.txt "ap
Perhaps this answer about registers might help you.
Alternative if you want to add APPEND to another buffer:
:redir >> other_file.txt :g/pattern/
Links:: :help :g :help :redir :help :# :help :redir
source share