在VIM语法文件中,如何在结束匹配中使用开始匹配?

时间:2011-06-16 14:17:51

标签: vim syntax xquery

在VIM语法文件中,可以编写如下语法区域匹配:

syn region xqString start=+'+ end=+'+
syn region xqString start=+"+ end=+"+

我想写的是

syn region xqString start=+(['"])+ end=+\1+

其中\ 1是在start中找到的匹配项。关于如何做到这一点或者如果不可能的任何答案?

1 个答案:

答案 0 :(得分:1)

请参阅:help :syn-ext-match

  

外部匹配:syn-ext-match

     

这些额外的正则表达式项目在区域模式中可用:

        */\z(* */\z(\)* *E50* *E52*
\z(\) Marks the sub-expression as "external", meaning that it is can
be accessed from another pattern match.  Currently only usable
in defining a syntax region start pattern.

      */\z1* */\z2* */\z3* */\z4* */\z5*
\z1  ...  \z9     */\z6* */\z7* */\z8* */\z9* *E66* *E67*
Matches the same string that was matched by the corresponding
sub-expression in a previous start pattern match.

所以你可以做syn region xqString start=+\z(['"]\)+ skip=+\\.+ end=+\z1+