2

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="/support/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.

ezuk
  • 3,096
  • 3
  • 30
  • 41
  • why do I get the feeling this is in the post: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Ken Jun 23 '11 at 17:39

1 Answers1

5

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
Community
  • 1
  • 1
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • That works for the LHS, but what about the right-hand side? I'm trying to bind it into a shortcut for instantly deleting an attribute-value pair. – ezuk Jun 27 '11 at 08:55
  • Thank you! That definitely helps. It selects the RHS as well, which answers my original question fully. The deletion shortcuts you recommended do strange things, so I'm still having trouble deleting the selected string, but this regex absolutely works for selecting a complete attribute-value pair. Many thanks! – ezuk Jun 28 '11 at 07:41