I need to get all text between <Annotation> and </Annotation>, where a word MATCH occurs. How can I do it in VIM?
<Annotation about='MATCH UNTIL </Annotation> ' timestamp='0x000463e92263dd4a' href=' 5raS5maS90ZWh0YXZha29rb2VsbWEvbGFza2FyaS8QyrqPk5L9mAI'> <Label name='las' /> <Label name='_cse_6sbbohxmd_c' /> <AdditionalData attribute='original_url' value='MATCH UNTIL </Annotation> ' /> </Annotation> <Annotation about='NO MATCH' href=' Cjl3aWtpLmhlbHNpbmtpLmZpL2Rpc3BsYXkvbWF0aHN0YXRLdXJzc2l0L0thaWtraStrdXJzc2l0LyoQh_HGoJH9mAI'> <Label name='_cse_6sbbohxmd_c' /> <Label name='courses' /> <Label name='kurssit' /> <AdditionalData attribute='original_url' value='NO MATCH' /> </Annotation> <Annotation about='MATCH UNTIL </ANNOTATION> ' score='1' timestamp='0x000463e90f8eed5c' href='CiZtYXRoc3RhdC5oZWx zaW5raS5maS90ZWh0YXZha29rb2VsbWEvKhDc2rv8kP2YAg'> <Label name='_cse_6sbbohxmd_c' /> <Label name='exercises_without_solutions' /> <Label name='tehtäväkokoelma' /> <AdditionalData attribute='original_url' value='MATCH UNTIL </ANNOTATION>' /> </Annotation>
Does it have to be done within vim? Could you cheat, and open a second window where you pipe something into more/less that tells you what line number to go to within vim?
— edit —
I have never done a multi-line match/search in vi[m]. However, to cheat in another window:
will show the elements/blocks for ‘tag’ (or other longer matching names), with line numbers, in less, and you can then search for the other text within each block.
Close enough?
— edit —
within ‘less’, type
to search for occurrences of MATCH. On the left margin will be the line number where that instance (within the targeted element/tags) is.
within vi[m], type
where ‘n’ is the desired line number.
Of course, if what you really wanted to do was some kind of search/yank/replace, it’s more complicated. At that point, awk / perl / ruby (or something similar which meets your tastes … or xsl?) is really the tool you should be using for the transformation.