一直在到处寻找这个。假设我有一个像这样的 XML block :
<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>
我想使用 Vim 快速跳转到(或删除)属性及其值。执行此操作的良好正则表达式是什么?
我尝试了明显的 /.*=".*?"
但它太贪婪了——如果我在同一行上有两个属性,它就会选择它们。
任何帮助将不胜感激。我专门寻找正则表达式而不是插件。
最佳答案
在 vim 中非贪婪运算符是 \{-}
因此你可以搜索:
/ [a-z]\{-}=
匹配每个属性的 LHS。
更新:基于以下 OP 的评论:
使用以下非贪婪搜索模式来搜索/匹配属性,完全假设 "
已在属性的 RHS 上的任何位置使用:
/[a-z]\{-}="[^"]\{-}"
要将光标移动到搜索模式的开头,请使用:
//
要将光标移动到搜索模式的末尾,请使用:
//e
最后要删除整个搜索模式,请使用:
d///e
关于xml - Vim 中匹配属性和值的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6458187/