vim regex not need \ to escape

5,527

Preceding your pattern with \v will make the pattern “magic”, and symbols like { and [ have an interpreted meaning (and literals need to be escaped).

So /\vsp{1,} would find what you wanted (I just tested it).

You can make this a sort of default by remapping / to /\v with the following lines in your vimrc:

nnoremap / /\v
vnoremap / /\v

See :help pattern for more.

Share:
5,527
James Andino
Author by

James Andino

A Functional Human Being

Updated on September 18, 2022

Comments

  • James Andino
    James Andino over 1 year

    In Vim is there an option to write regexs in the same style as Awk for example

    /sp\{0,\}/
    Would be

    /sp{0,}/

  • James Andino
    James Andino over 12 years
    This was all good info and very useful. Is there a way to turn of the escaping of special characters in vim?
  • Kevin
    Kevin over 12 years
    I see what you mean now. I seriously doubt it, that would almost certainly require a different parser developed in parallel, and I doubt it would be a feature with enough demand to justify that extra implementation and maintenance.