Vim’s :g takes two inputs, a pattern and an operation, and it runs that operation on
each line that matches the pattern in the current file. :g is a tool whose usage isn’t imposed on
you nor even readily apparent, so its usefulness is proportional to your
creativity.
One cool way I like to use :g is to bundle up related lines that are currently
scattered across a file.
The lines that I care about are the lines that are commented out, in one fell
swoop I’d like to bundle those lines together and put them neatly at the top.
Here’s how to do it:
:g is one of the most underrated features in Vim, read more about it with :h :g.
Here’s another way to do the same thing, delete and store the lines into the
register q and the put the contents of the register in line 0:
:g/^"/d Q
:0pu q
Use lowercase named registers, a-z, to have the register’s previous contents replaced
and use uppercase named registers, A-Z, to have the register’s previous contents
appended to.