在Vim命令中\ _< =和\ @ =是什么意思?

时间:2014-04-28 01:14:21

标签: vim

无法理解\@<=\@= Benoit对此post的回答,任何人都可以帮忙解释一下吗?

1 个答案:

答案 0 :(得分:2)

From vim documentation for patterns

\@= Matches the preceding atom with zero width. {not in Vi}
    Like "(?=pattern)" in Perl.
    Example         matches 
    foo\(bar\)\@=       "foo" in "foobar"
    foo\(bar\)\@=foo    nothing

                            */zero-width*
    When using "\@=" (or "^", "$", "\<", "\>") no characters are included
    in the match.  These items are only used to check if a match can be
    made.  This can be tricky, because a match with following items will
    be done in the same position.  The last example above will not match
    "foobarfoo", because it tries match "foo" in the same position where
    "bar" matched.

    Note that using "\&" works the same as using "\@=": "foo\&.." is the
    same as "\(foo\)\@=..".  But using "\&" is easier, you don't need the
    braces.


\@<=    Matches with zero width if the preceding atom matches just before what
    follows. |/zero-width| {not in Vi}
    Like '(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns.
    Example         matches 
    \(an\_s\+\)\@<=file "file" after "an" and white space or an
                end-of-line
    For speed it's often much better to avoid this multi.  Try using "\zs"
    instead |/\zs|.  To match the same as the above example:
        an\_s\+\zsfile

    "\@<=" and "\@<!" check for matches just before what follows.
    Theoretically these matches could start anywhere before this position.
    But to limit the time needed, only the line where what follows matches
    is searched, and one line before that (if there is one).  This should
    be sufficient to match most things and not be too slow.
    The part of the pattern after "\@<=" and "\@<!" are checked for a
    match first, thus things like "\1" don't work to reference \(\) inside
    the preceding atom.  It does work the other way around:
    Example         matches 
    \1\@<=,\([a-z]\+\)  ",abc" in "abc,abc"