Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VIM have its own regex syntax?

Tags:

regex

vim

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?

like image 673
user210757 Avatar asked Aug 30 '10 22:08

user210757


People also ask

Does VIM use regex?

Using Regex in VimMany of Vim's search features allow you to use regular expressions. Some of them are: The search commands ( / and ? ) The global and substitute command-line (ex) commands ( :g and :s )

What kind of regex does Vim use?

vim has a mixed up regex syntax.

Does VI support regex?

vi Regular Expressions(period) Matches any single character except a newline. Remember that spaces are treated as characters. Matches zero or more (as many as there are) of the single character that immediately precedes it. The * can follow a metacharacter, such as . , or a range in brackets.

Is regex the same as regular expression?

A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.


2 Answers

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.

like image 142
Gian Avatar answered Sep 25 '22 04:09

Gian


There is a plugin called eregex.vim which translates from PCRE to Vim's syntax. It takes over a thousand lines of vim to achieve that translation!

like image 28
Evgeni Sergeev Avatar answered Sep 25 '22 04:09

Evgeni Sergeev