7

Within Vim to group some chars sequence usage of \( \) is required. The same behavior is for other specials: \{ \}.

Is it possible to change regex style to be like in perl? How to switch it?

Instead

\\(

I would

(

???

1 Answer 1

11

You can change the default required 'magic level'

:se nomagic
:se magic

See :he magic

I'd recommend using the corresponding escapes instead to avoid breaking your other mappings.

 /\v(\d+)

will match consecutive digits like you'd expect with Perl Regex

From pattern.txt help:

Examples:
after:    \v       \m       \M       \V         matches ~
                'magic' 'nomagic'
          $        $        $        \$         matches end-of-line
          .        .        \.       \.         matches any character
          *        *        \*       \*         any number of the previous atom
          ()       \(\)     \(\)     \(\)       grouping into an atom
          |        \|       \|       \|         separating alternatives
          \a       \a       \a       \a         alphabetic character
          \\       \\       \\       \\         literal backslash
          \.       \.       .        .          literal dot
          \{       {        {        {          literal '{'
          a        a        a        a          literal 'a'

{only Vim supports \m, \M, \v and \V}

It is recommended to always keep the 'magic' option at the default setting,
which is 'magic'.  This avoids portability problems.  To make a pattern immune
to the 'magic' option being set or not, put "\m" or "\M" at the start of the
pattern.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.