tags:

views:

194

answers:

1

Why do you have to make your regex "very magic" so that you don't have to escape your capture quotes? And if you set your environment to very magic, you are non-standard and may have compliance issues. I am just wondering why vim uses a different regex syntax than say, perl?

+9  A: 

Most vi (and therefore vim) features were derived from ed. vi and ed both predate perl by at least a decade or two. A better question might be "why doesn't Perl use the same regex syntax as vi?".

Of course, one could also argue that the kinds of regular expressions that one would wish to write inside a text editor to perform common tasks are probably rather different to those you might wish to write inside a programming language.

Gian
True, but personally, IMO, there's already too much fragmentation in developer mindspace. PCRE's are pretty much an "industry standard". One of the things I love about VIM is how many options it has. Using PCRE as the search/replace engine should be at least allowed as a ./configure flag
Bryan Ross
It's an open source product. If this is a killer feature for you, why not implement it and submit it as a patch? Maybe there are others who feel the same way and would benefit from this.
Gian
@Bryan: Vim's regex has a ton of features not available in PCRE - everything starting with `\%` or `\\_`.
too much php
@too much php Why `\\_`? I like handling of end-of-line by PCRE more then by vim: `[^\n]` will match everything (including `\n`) in vim and everything except `\n` in PCRE, which is strange (but documented). `\%$` and `\%^` are not needed in PCRE because we have /m and /s flags, so PCRE lacks only match at given position feature. And there are plenty of features in PCRE, that lack in vim (`\p{}`, normal unicode handling, `[\uXXXX-\uYYYY]` where `YYYY-XXXX` is greater then 255, recursive regular expressions, >9 capture groups, ...).
ZyX
@Bryan: because \_s is easier than [ \t\r\n]. There are still many plugins and features that rely on the vim regex syntax, so it would be tricky to compile it in. (Admittedly, if you got it working I'd be using it all day ...)
too much php
@too much php Not `[ \t\r\n]`, but only `[\s\n]`. Conversion of `\r\n` into single linebreak is done before using a regular expression and does not apply to strings (`echo match("\r", '\\_s')` will always show -1). And matching `\r\n` as a single `\n` is also possible in perl. There are two other features that vim has and PCRE has not: non-fixed-length lookbehind and branches (last can be replaced with lookaheads). Note that columns can be replaced with lookbehinds (though it is not so trivial).
ZyX
I guess compiling vim with the +perl feature is good enough. Totally forgot about that.
Bryan Ross