Search notes:

vim option: magic

The (boolean) value of magic specifies how the backslash changes the meaning of the following character when constructing regular expressions.

nomagic

If the value turned *off (or to nomagic), all except three characters match themselves. The three exceptions are
So, in nomagic mode, ..f* matches only if it finds exactly two dots followed by one f followed by a star.
In order to use the full power of the regular expression notation, a lot of backslashes are required. In order to match any two characters followed by zero or more f's, the following pattern must be used: \.\.f\*.

magic

The intention of magic is to make it easier for the user to enter regular expression by removing the requirement to precede a regular expression instruction with a backslash.
This mode is magic because characters magically change their meaning.
These three characters are *, . and ~, resulting in the following three differences between magic and nomagic:
magic nomagic meaning
* \* Zero or more
. \. Any character
~ \~ Latest substitute string

Very magic

Very magic goes a step further than magic.
With very magic, all ASCII characters except 09, aA, AZ and _ become a a special meaning. In this mode, searching for text becomes very magic.
In order to formulate a regular expression in very magic mode, the regular expression must be preceded by \v.

Changing the default of magic to nomagic

It is adviced not to set nomagic in VIM scripts prior to VIM 9 script because this might break scripts that rely on having magic (which the default) set.
This becomes less of a problem with VIM 9 scripts because they ignore the value of magic.
It is also possible to force a regexp-pattern to be interpreted as though magic was set by using \m and to be interpreted as though nomagic was set by using \M. (See also \v and \V)

See also

vim options

Index