3

After years of using Vim and then Neovim, I still find myself forgetting to escape parenthesis and the | character when I intend to use their special behaviour:

If I want to search for "this" or "that", this is incorrect:

/(this|that)/

Instead, I should have typed one of these two alternatives:

/\(this\|that\)/
/\v(this|that)/

I either have to backslash the (, |, and ) characters, or I have to use \v to enter "very magic" mode. From the docs:

\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'

How do I make \v the default mode, without having to type \v at the beginning of the regex?

2
  • 4
    nnoremap / /\v is a very common mapping.
    – romainl
    Jan 11 at 7:29
  • @romainl That looks useful. Is there something similar for substitutions?
    – Flimm
    Jan 11 at 7:59

0

Your Answer

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

Browse other questions tagged or ask your own question.