Vim 语法文件与 \zs 不匹配 [英] Vim syntax file not matching with \zs

查看:37
本文介绍了Vim 语法文件与 \zs 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过更改 fsharp 语法文件中的这一行来提高效率(来自 this 插件)来自:

I am trying to obtain some effeciency improvements by changing this line in my fsharp syntax file (from this plugin) from:

syn match    fsharpModule     "\%(\<open\s\+\)\@<=[a-zA-Z.]\+"  

syn match    fsharpModule     "\%(\<open\s\+\)\zs[a-zA-Z.]\+"

因为 "\@<=" 结构上的文档指出:

since the docs on the "\@<=" construct states that:

为了速度,避免这种多重通常要好得多.尝试使用 "\zs" 代替 |/\zs|.

For speed it's often much better to avoid this multi. Try using "\zs" instead |/\zs|.

然而,这不起作用,并且没有高亮

However, this doesn't work and there is no highligting for

open SomeModule  

这怎么可能?在使用第一个和第二个匹配模式时,在 vim 中进行常规搜索(使用/)会突出显示SomeModule".

How can this be? Doing a regular search in vim (with /) highligts the 'SomeModule' both when using the first and the second match pattern.

推荐答案

这是由语法包含引起的,并且因为您尝试断言的 open 关键字存在另一个语法组.

This is caused by the syntax containment and because another syntax group exists for the open keyword that you're trying to assert.

在语法高亮中,\zs 只影响结果(Vim 会用语法组高亮什么);当涉及到与其他语法组的关系时,整个模式(即包括 \zs 之前的文本)被视为匹配.(此实现细节未在帮助中明确记录.)相比之下,正面回顾断言(\%(...\)\@<=),既不包含在结果中也不包含在实际匹配中.这解释了您所看到的行为差异.(它与@rmunn 怀疑的可选分组无关,也与@Sergio 的回答中的多行无关,因为 \s\+ 不允许在中间换行.)

Within syntax highlighting, \zs only affects the result (what Vim will highlight with the syntax group); the whole pattern (i.e. including the text before the \zs) is treated as the match when it comes to relationships with other syntax groups. (This implementation detail is not explicitly documented in the help.) The positive lookbehind assertion (\%(...\)\@<=), by contrast, is neither included in the result nor the actual match. That explains the difference in behavior that you see. (It has nothing to do with the optional grouping, as @rmunn suspected, nor with multiple lines as per @Sergio's answer, as \s\+ will not allow a linebreak in between.)

我认为这里易于实现更重要,所以使用 \@<= 应该没问题,即使帮助推荐 \zs.如果您愿意完全重构语法脚本,可以通过以下方式解决此问题,假设某处有 syntax 关键字 fsharpOpen open:

I think ease of implementation is more important here, so it should be fine to use \@<=, even though the help recommends \zs. If you're willing to completely restructure the syntax script, this could be solved with something along these lines, assuming there's a syntax keyword fsharpOpen open somewhere:

syntax keyword fsharpOpen nextgroup=fsharpModule skipwhite open
syntax match fsharpModule "[a-zA-Z.]\+" contained

这篇关于Vim 语法文件与 \zs 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆