Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change vim regexp dialect?

Tags:

regex

vim

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

(

???

like image 377
Max Avatar asked Nov 01 '11 08:11

Max


1 Answers

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.
like image 98
sehe Avatar answered Sep 21 '22 00:09

sehe