11

While editing syntax file, I found something like:

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

I'm familiar with any other than \% and \@ there. I can't even googling because I don't know what is it's name. So what it is and what it does?

1 Answer 1

15

Before googling, try the doc:

From :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}

And :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 "//"
8
  • 1
    Ah, I don't know that :help can accept pattern as argument. That's very valuable info. By the way, it does doesn't have a name, doesn't it?
    – Mas Bagol
    Aug 17, 2016 at 14:04
  • 1
    It doesn't exactly accept patterns as arguments: the pattern.txt file has topics about these items thus they have an help tag associated (/\%(\) or /\%( or E53 for the first one and /\@<! for the second one) and these tags can be used as arguments of :h. Now about their name, I'd say they are called atoms just like ^ or ., but I'm not 100% sure.
    – statox
    Aug 17, 2016 at 14:08
  • 5
    @statox It doesn't exactly accept patterns as arguments - Well, that's what :helpgrep is for. :)
    – lcd047
    Aug 17, 2016 at 16:03
  • 2
    This site tends to surprise me sometimes: Currently I made 170 answers and this one is the 6th most upvoted while it only contains only two easy to find quotes of the doc whereas I have other answers with vimscript code or how to realize more complex actions... I don't get why this one is so "successful"
    – statox
    Aug 18, 2016 at 7:31
  • 1
    @statox Lots of meat on this bone. :) I've considered starting a conversation in Meta on topic but there's always something else vying for my attention. We're on the same page so far, e.g. agree about votes being generally meaningful/appropriate if somewhat underwhelming w/r/t quantity and about it seeming like there's a bot (or very dedicated person!) bumping new posts. Actually, proof of a bot would be kind of depressing because that would mean a lot of my answers couldn't muster a single human being's approval. :D Cheers!
    – B Layer
    May 13, 2020 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.