Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Vim's flavor of regex #3996

Open
3 of 9 tasks
J-Fields opened this issue Aug 26, 2019 · 10 comments
Open
3 of 9 tasks

Support Vim's flavor of regex #3996

J-Fields opened this issue Aug 26, 2019 · 10 comments

Comments

@J-Fields
Copy link
Member

J-Fields commented Aug 26, 2019

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
Copy link

Banger commented Jul 20, 2020

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
Copy link

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
Copy link
Contributor

sql-koala commented Feb 3, 2021

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
Copy link
Member Author

J-Fields commented Feb 4, 2021

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.

J-Fields added a commit that referenced this issue Oct 3, 2021
Central to this refactor is a rationalization of pattern parsing - we now have an immutable`Pattern` class with its own Parsimmon parser; it's now used everywhere.

A few enhancements, such as supporting `/{pattern}/` as line specifier in line range

And some bugs fixed:
- `\n` now expands to `\r?\n` (to work with CRLF files)
- `\<` and `\>` (word boundaries) are now mapped to `\b`

Refs #3996
@J-Fields J-Fields changed the title Support vim's flavor of regex Support Vim's flavor of regex Oct 20, 2021
@J-Fields J-Fields added this to the Backlog milestone Oct 20, 2021
@JohnnyUrosevic
Copy link
Contributor

JohnnyUrosevic commented Nov 10, 2021

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
Copy link
Member Author

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
Copy link
Contributor

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
Copy link

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: #7499 (comment)

@rdbisme
Copy link

rdbisme commented Jul 8, 2022

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

@ahmafi
Copy link

ahmafi commented Aug 22, 2023

%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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants