Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/vimscript/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,13 @@ export class Pattern {
caseOverride,
ignoreSmartcase: args.ignoreSmartcase ?? false,
});

const jsPatternString = Pattern.convertToJsCompatiblePattern(patternString);

return new Pattern(
patternString,
args.direction,
Pattern.compileRegex(patternString, ignoreCase),
Pattern.compileRegex(jsPatternString, ignoreCase),
inSelection ?? false,
closed,
emptyBranch,
Expand All @@ -328,6 +331,10 @@ export class Pattern {
return configuration.ignorecase;
}

private static convertToJsCompatiblePattern(patternString: string): string {
return patternString.replace(/\\\(/g, '(').replace(/\\\)/g, ')');
}

private constructor(
patternString: string,
direction: SearchDirection,
Expand Down
7 changes: 7 additions & 0 deletions test/search/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ suite('Search (/ and ?)', () => {
end: ['', 'one tw|o2o'],
});

newTest({
title: '/ can search with regex groupings (search for sequence of aX where X is not b)',
start: ['|', 'ab ac'],
keysPressed: '/a\\([^b]\\)\n',
end: ['', 'ab |ac'],
});

newTest({
title: '/ can search with newline',
start: ['|asdf', '__asdf', 'asdf'],
Expand Down