I have been using some variation of Vim on and off since ~2012. And in that time I have learned staggeringly little about the editor. In comes Vim Golf.
Long story short, today I learned about the :g
command. g
is short for global and
lets you run an Ex
command across all lines matching some pattern in your current
buffer. This can be used to quickly do things like:
:g/^\s*&/d
.:g/^\s*# */d
.a
: qaq:g/pattern/y A
(where qaq
starts recording a macro into register a
and immediately exits, leaving a
empty and
y A
appends to register a
each line matched)