guettli guettli - 3 months ago 19
Perl Question

vim: Interactive search and replace with perl compatible regular expressions

According to this page you can use perl compatible regular expression with

:perldo s/pattern/insert/g
.

This works fine.

But, how can I get interactive search and replace with PCRE syntax in vim?

Since this does not work with
perldo
I search for a different solution.

Answer

Till the current release version of vim, there is no way to do :s/[perlRegex]/bar/c

So you are asking for a feature that doesn't exist.

You can do matching with verymagic, however it is not Perl Regex compatible flag. It is still using the vimregex engine, just changed the way of escaping regex patterns.

For example, in perl, you can do lookahead/behind (?<=foo)..., (?=foo), (?!foo).., you can use the handy \K : som.*ing\Kwhatever etc, you cannot use those syntax in vim directly, no matter which 'magic' level you have set. Vim has the same feature, but different syntax:

\@=
\@!
\@<=

and also the \zs \ze are very handy, even more powerful than perl's \K.

Vim is an Editor, with vim regex, you can not only do text matching, but also match base on visual selection, cursor position and so on.

If you really need to do complex pattern matching and really need do them in vim, learn vim regex! It is not difficult for you if you "know pcre very well"