On 12/04/2010 11:42 AM, Ada wrote:
I have a long xml just like this:
<events>
<event type="normal">
</event>
<event type="wait" duration="10"/>
<event type="normal">
</event>
<event type="normal">
</event>
....
</events>
Now I want to insert some number attributes just like this:
<events>
<event num="1" type="normal">
</event>
<event num="2" type="wait" duration="10"/>
<event type="normal">
Curious why this one didn't get num="3"
</event>
<event num="3" type="normal">
making this one num="4"
</event>
....
</events>
You can use
:let i=0 | g/<event\>/let i+= 1 | s/<event\>\zs/\=' num="'.i.'"'
This assumes that only one <event> tag will occur on a line, not
<event type="foo" /><event type="bar" />
-tim
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php