Vim Tips Wiki
Advertisement
Tip 1237 Printable Monobook Previous Next

created May 22, 2006 · complexity basic · author Peter Hodge · version 5.7


If you love regular expressions, you probably like to use them everywhere. Unfortunately it gets very confusing when you use Vim's regular expressions, Perl and POSIX compliant varieties in PHP, and then command-line grep as well, because they all seem to have different rules as to which characters have special meaning on their own and which do not. Quite often I need several attempts to write a search pattern because I can't remember which characters need to be preceded by a backslash.

Thankfully, any Vim search pattern can include the special sequence '\v' (for 'very magic'), and this will make every following character except a-zA-Z0-9 and '_' have special meaning. Using '\V' has the opposite effect, all characters have their literal meaning and must be preceded by '\' to activate their special meaning. So when I've been using another regex flavour for a while and have forgotten which characters have special meaning in Vim, I just start the pattern with \v or \V to them all on or off, and I can also rest assured that my search patterns are portable because they don't rely on the 'magic' option.

References

Comments

You can use :snomagic to do the same as \V. It can be abbreviated to :sno


Advertisement