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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.