How do I yank all matching lines into one buffer?

:g/^match/yank A

This runs the global command to yank any line that matches ^match and put it in register a. Because a is uppercase, instead of just setting the register to the value, it will append to it. Since the global command run the command against all matching lines, as a result you will get all lines appended to each other.

What this means is that you probably want to reset the register to an empty string before starting: :let @a="" or qaq (i.e., recording an empty macro).

And naturally, you can use the same with any named register.


  • :help registers
  • :help quote_alpha
  • :help global
  • Using Vi/Vim: Ex and Ex-like Commands

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)