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?
nnoremap / /\v
is a very common mapping.