-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow regex in / search #627
Conversation
My big concern is I'm not quite sure how well Vim regexp maps to JS regexp. Would you mind doing a little research to see if it is a fairly close mapping or not? |
Sounds good. Hopefully they're close... |
I hope so too. Or close enough that you can use a meta regex to translate the normal regex to a js re... oh god, what am I saying? |
@sectioneight the regex we use here is the same as Vim Substitution Vim/src/cmd_line/commands/substitute.ts Line 64 in 7ac106d
For now I'm using JS's regex in substitution, I'm not quite sure if ppl are satisfied with it but I don't see any complains yet (maybe they don't notice its existence yet). You may want to write some JS regex to translate Vim's regex to JS's regex ... |
Yes, I've found: https://github.com/othree/eregex.vim/blob/master/plugin/eregex.vim To translate Vim regex to PCRE, but of course JS is not PCRE. There's also https://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines but it's pretty high level. Sounds like a good first pass would be to use JS regex for search. But I'm open to suggestions. |
Yiiiikes. If it's too complicated, let's just do JS regex for now and see if anyone complains. 😉 |
7eeb859
to
e31a63b
Compare
This PR is good to go IMO. |
It still says WIP on it - @sectioneight is this good to go? |
Still need to add a test or two, but it sounds like you guys approve of the approach. |
I do; I'm very much a fan of 80% solutions, especially when people very rarely use the other 20%. Ping me when it's good to go. :) |
As am I. Will get some tests in tomorrow and ping you for review.
|
e31a63b
to
343779b
Compare
343779b
to
bcaeba6
Compare
Ok, ready for review @johnfn |
@@ -782,7 +782,7 @@ export class CommandSearchForwards extends BaseCommand { | |||
isMotion = true; | |||
|
|||
public async exec(position: Position, vimState: VimState): Promise<VimState> { | |||
vimState.searchState = new SearchState(SearchDirection.Forward, vimState.cursorPosition); | |||
vimState.searchState = new SearchState(SearchDirection.Forward, vimState.cursorPosition, "", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but I'm trying to move towards a style where we explicitly name all our boolean arguments. Something like { isRegex: true }
is what I'm thinking here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
Only one small comment. I think this PR is going to have a big impact for such a small LOC difference! :) |
I'm going to update one more thing on this PR. Right now if you have a partial regex (e.g. |
@@ -280,10 +295,11 @@ export class SearchState { | |||
} | |||
} | |||
|
|||
constructor(direction: SearchDirection, startPosition: Position, searchString = "") { | |||
constructor(direction: SearchDirection, startPosition: Position, searchString = "", { isRegex = false } = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure about this syntax (still a TS noob). Is this what you were thinking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that looks fine to me!
OK, I think we're finally ready to go here |
Ping for review |
const regex = new RegExp(search.replace(SearchState.specialCharactersRegex, "\\$&"), ignorecase ? 'gi' : 'g'); | ||
let searchRE = search; | ||
if (!this.isRegex) { | ||
searchRE = search.replace(SearchState.specialCharactersRegex, "\\$&"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very cool. I never knew about $&.
Thanks for the ping. Feel free to ping me on here/slack if I don't review within ~24h. That is almost certainly an indicator that it just slipped through the cracks. |
And thanks for the PR, of course :) |
Does this PR support searching for new lines? If so, how? We've tried:
|
@shaunluttin ,i have same problem. :( |
No, it doesn't support newline search yet. Feel free to open an issue. |
Fixes #572