vimtricks.wiki Concise Vim tricks, one at a time.

How do I use regular expressions without escaping special characters?

Answer

/\v pattern

Explanation

The \v flag enables "very magic" mode in Vim regex, where most special characters work like standard regular expressions without needing backslashes.

How it works

  • /\v makes +, ?, |, (, ), {, } all special by default
  • Without \v, you must escape these: \+, \?, \|, \(, etc.
  • This makes patterns read more like standard regex

Example

Searching for one or more digits:

  • Standard Vim: /[0-9]\+
  • Very magic: /\v[0-9]+

Searching for "cat" or "dog":

  • Standard Vim: /cat\|dog
  • Very magic: /\v cat|dog

Tips

  • \V is "very nomagic" — only \ is special (literal search)
  • \m is the default "magic" mode
  • \M is "nomagic" mode
  • Very magic mode is closest to Perl/PCRE regex syntax

Next

How do you yank a single word into a named register?