Say we have the following code:
Lorem ipsum.
<input name="test1">
<input name="test2"> Lorem ipsum some long text possibly so long you lose your overview.
<input name="test3">
Lorem ipsum.
Now when I do
g/name="[^"]*"/p
the output will be:
<input name="test1">
<input name="test2"> Lorem ipsum some long text possibly so long you lose your overview.
<input name="test3">
My desired output is:
name="test1"
name="test2"
name="test3"
What's the quickest way to print out ONLY the match, not the entire matching line?
p
is actually the independent command:p
... with no knowledge of the pattern in:g
. (Some people confuse it for something more like:s///p
.) If you follow:g
with a command that does what you want for a single line then:g
will make sure it gets run on the range of lines.:g/name="[^"]*"/norm "Aygn
to append all matches to register a. But sadly, this only works if there is at most 1 match in the line.