I know \(...\) is Vim's way to create a capturing group. It was listed under the atom entry in Vim's doc. There are two other forms of atom, \%(...\) and \z(...\). The document is not very clear on what exactly does they do. Could anyone help to explain it please?


/\%( permits to define a group as with /\(, but we cannot refer to text matched by this group with /\1 or with submatch() from commands like :substitute or functions like matchlist().

Having a group permits to apply counting and other things to the group (/star, /\+, /\?...)

While /\%( hides, /\z( seems to do the opposite, it exports a group found outside the context where it has been found. It seems to apply only to syntax highlighting. I've never used it.

| improve this answer | |
  • 1
    Thanks for the explanation! So \%( is kind of like non-capturing group to me. – Just a learner May 13 at 7:49
  • 3
    This is exactly a non capturing group. – Luc Hermitte May 13 at 7:50
  • 4
    Yes, /\z( is only valid for syntax highlighting definitions, because you need to define start and end patterns and you might want to make sure, that the part matched in a start pattern is also in an end pattern available – Christian Brabandt May 13 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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