Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

/sp\{0,\}/
Would be

/sp{0,}/

share|improve this question

3 Answers 3

up vote 7 down vote accepted

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|improve this answer
    
Thank you that will help keep things simple. –  James Andino Oct 28 '11 at 13:41

/sp\{0,}

Of course for {0,}, you would be better off using *: /sp* would (same as the above) find an 's' followed by zero or more p's. Note that zero or more is always true, so there's no reason for it in this particular expression.

share|improve this answer
    
This was all good info and very useful. Is there a way to turn of the escaping of special characters in vim? –  James Andino Oct 27 '11 at 20:00
    
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. –  Kevin Oct 27 '11 at 20:10

Vim does not have an option to emulate awk-style regular expressions, no. There are a lot of dialects of regex, and unfortunately there are always these little dialectical differences to keep track of when going from one tool to another.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.