开发者

Regex for matching attributes and values in Vim

Have been looking all over the place for this. Suppose I have a block of XML like this:

<leftcol>
    <block icon="tips" text="Is it right for you?" url="/support/feasibility.html" link="Feasibility              evaluation"/>
    <block icon="question" text="Interested?" url="/suppor开发者_开发百科t/question.html" link="Ask a question"/>
    <block icon="docs" text="Want some details?" url="/docs/" link="View documentation"/>
    <block icon="box" text="Like It?" url="/purchase.html" link="Purchase online"/>
</leftcol>

And I want to use Vim to quickly jump to (or delete) attributes and their values. What would be a good regex to do this?

I tried the obvious / .*=".*?" but it's too greedy -- if I have two attributes on the same line, it selects them both.

Any help would be much appreciated. I'm specifically looking for a regex and not a plugin.


In vim non-greedy operator is \{-} threfore you can search on:

/ [a-z]\{-}=

to match LHS of each and every attribute.

UPDATE: Based on OP's comments below:

Use following non-greedy search pattern to search/match an attribute completely assuming " has been used everywhere on RHS of an attribute:

/[a-z]\{-}="[^"]\{-}"

To move your cursor to the beginning of a search pattern use:

//

To move your cursor to the end of a search pattern use:

//e

And finally to delete entire search pattern use:

d///e
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜