vim regex中'\%'和'\ @'令牌的名称是什么?它是做什么的?


10

在编辑语法文件时,我发现类似以下内容:

\s*\%(\%(:\@<!\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$

除了那里以外\%,我都不熟悉\@。我什至无法搜索,因为我不知道它的名字。那么它是什么,它做什么呢?

Answers:


14

谷歌搜索前,请尝试以下文档:

:h \%

\%(\)   A pattern enclosed by escaped parentheses.
    Just like \(\), but without counting it as a sub-expression.  This
    allows using more groups and it's a little bit faster.
    {not in Vi}

:h \@<!

\@<!    Matches with zero width if the preceding atom does NOT match just
    before what follows.  Thus this matches if there is no position in the
    current or previous line where the atom matches such that it ends just
    before what follows.

    Like "(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns.
    The match with the preceding atom is made to end just before the match
    with what follows, thus an atom that ends in ".*" will work.
    Warning: This can be slow (because many positions need to be checked
    for a match).  Use a limit if you can, see below.

    Example         matches ~

    \(foo\)\@<!bar      any "bar" that's not in "foobar"

    \(\/\/.*\)\@<!in    "in" which is not after "//"

1
啊,我不知道:help可以接受模式作为参数。这是非常有价值的信息。顺便说一句,它没有名字,不是吗?
Mas Bagol '16

1
它不完全接受的模式作为参数:该pattern.txt文件包含有关这些项目的主题因此他们有帮助标签相关的(/\%(\)/\%(E53为第一个和/\@<!第二个之一),这些标签可以作为论据:h。现在,关于它们的名称,我想说它们被称为原子,就像^或一样.,但我不确定100%。
statox

4
@statox 它并不完全接受模式作为参数 - :helpgrep就是这样。:)
lcd047

@ lcd047该死的我怎么会忘记这个命令?感谢您的帮助:)
statox

1
这个站点有时会使我感到惊讶:目前,我回答了170个问题,而这个问题是排名第六的,而它仅包含两个易于找到的文档引号,而我还有其他关于vimscript代码或如何实现更复杂动作的回答。 ..我不明白为什么这个是如此“成功”
statox
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.