Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional regex in vim?

Is it possible to do conditional regex (like the one described in http://www.regular-expressions.info/conditional.html) in Vim?

like image 392
Vineeth Avatar asked May 25 '10 00:05

Vineeth


2 Answers

Vim regex does not have this feature, so you will need to use a bit of repetition to create the same behaviour:

/\(\%(condition\)\@=then\|\%(condition\)\@!else\)

Note that you have to use the condition twice in the Vim version and the lookahead/lookbehind must always be the opposite in the then/else parts otherwise your regex will not be correct.

like image 133
too much php Avatar answered Sep 19 '22 11:09

too much php


Not natively, however if you have +perl in vim you should be able to use

:perldo s/search/replace/
like image 35
Todd Hunter Avatar answered Sep 22 '22 11:09

Todd Hunter