VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.97k stars 1.32k forks source link

Support Vim's flavor of regex #3996

Open J-Fields opened 5 years ago

J-Fields commented 5 years ago

We currently use javascript's regex library, which is unfamiliar to some coming from vim (see #2043, #3073, #3075, etc.). This ticket is to consolidate those and center discussion around the possibility of supporting Vim's regex flavor.

As a first step, I've created the Pattern class with its own parser - this essentially just translates a Vim-style regex into a JS-style regex.

Current status:

Banger commented 4 years ago

Very interested in this. The whole point of using the VIM extension is so I don't have to learn yet another editor and its quickiness. You should look into VIM implementations in javascript. There are a lot (not many good ones though).

FrankCoder commented 3 years ago

If this ever gets integrated, I believe it would be a good to have the option. I've been heavily using a variety of regex engines for more years than I care to say and I always thought Vim's regex syntax was clunky.

sql-koala commented 3 years ago

I think there is another option with less effort than a full regex engine. I am stealing ;-) this idea from vsvim. What the guys there did, is a "tokenwise" translation. Meaning:

\<  -> \b
\l  -> [a-z]

And so on... A lot of vim regex could be translated like so and you can also do a lot with simple "left to right" translation, meaning no full parsing. Limits are where functionality is principally missing in js regex.

J-Fields commented 3 years ago

Yeah that's a good point, @sql-koala, I've pondered it before. There are definitely limitations, but it'd be a good first solution I think.

JohnnyUrosevic commented 3 years ago

Hey guys, I imported a .vimrc which has nnoremap / /\v and learned about the concept of 'very magic' in Vim which makes it so no regex characters need to be escaped in patterns. Is there any plans to add this in addition to magic / no magic? Vim also has \V for 'very no magic' (who named these things?) as well as \m and \M for setting magic and nomagic on the fly.

J-Fields commented 3 years ago

Is there any plans to add this in addition to magic / no magic?

Yes, support for magic is planned, though it may be a while before it's implemented

JohnnyUrosevic commented 3 years ago

Is there any plans to add this in addition to magic / no magic?

Yes, support for magic is planned, though it may be a while before it's implemented

I can try to work on this if you want. I don't know if there's more pressing issues you would rather have contributors for.

macintacos commented 2 years ago

Just noting here that with the new (fantastic!) inccommand addition, this issue makes it all the more puzzling when it seems like the RegEx matches, the UI updates, but it doesn't actually do anything because the RegEx doesn't match when doing the replace (from what I can tell). See this comment: https://github.com/VSCodeVim/Vim/issues/7499#issuecomment-1039755795

rdbisme commented 2 years ago

s:(\S+):"\1":g shows the replacement correctly in the UI, but then it provides E486: Pattern not found when hitting enter.

ahmafi commented 1 year ago

%s/stroke=".*?"/stroke="currentColor" also highlights the replacement correctly in the editor, but then it shows E486: Pattern not found: stroke=".*?" when I try to replace.