I have a document containing titles and codes. Each got their own line and now I need to copy all codes out of it, each in a separate line. They all start with numbers and Vim can probably do it with ease.
The document looks like this:
TITLE
123-456-4252-2
Other TITLE 2
123-456-4252-X
A nice TITLE 3
523-456-4252-2
...
You can use the :global
command!
qaq:g/^\d/y A
After this, the lines are in the a
register. Afterwards you can paste the copied lines with "ap
.
qaq
records a macro in a
and immediately ends it, effectively clearing it.:g/foo/bar
executes the bar
command for every line that matches foo
.^\d
is a regex that matches lines starting with a number.y A
yanks into the a
register, but in append-mode.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With