diff --git a/src/cmd_line/commands/grep.ts b/src/cmd_line/commands/grep.ts new file mode 100644 index 00000000000..84f78708abe --- /dev/null +++ b/src/cmd_line/commands/grep.ts @@ -0,0 +1,23 @@ +import { VimState } from '../../state/vimState'; +import { ExCommand } from '../../vimscript/exCommand'; +import { optWhitespace, Parser, regex } from 'parsimmon'; +import * as vscode from 'vscode'; + +export class GrepCommand extends ExCommand { + public static readonly argParser: Parser = optWhitespace + .then(regex(/.*/)) + .map((pattern) => new GrepCommand(pattern.trim())); + + private pattern: string; + private constructor(pattern: string) { + super(); + this.pattern = pattern; + } + + async execute(vimState: VimState): Promise { + vscode.commands.executeCommand('workbench.action.findInFiles', { + query: this.pattern, + triggerSearch: true, + }); + } +} diff --git a/src/vimscript/exCommandParser.ts b/src/vimscript/exCommandParser.ts index 66334625307..e3d4347b0aa 100644 --- a/src/vimscript/exCommandParser.ts +++ b/src/vimscript/exCommandParser.ts @@ -52,6 +52,7 @@ import { LineRange } from './lineRange'; import { nameAbbrevParser } from './parserUtils'; import { LetCommand } from '../cmd_line/commands/let'; import { CallCommand, EvalCommand } from '../cmd_line/commands/eval'; +import { GrepCommand } from '../cmd_line/commands/grep'; type ArgParser = Parser; @@ -247,7 +248,7 @@ export const builtinExCommands: ReadonlyArray<[[string, string], ArgParser | und [['fu', 'nction'], undefined], [['g', 'lobal'], undefined], [['go', 'to'], GotoCommand.argParser], - [['gr', 'ep'], undefined], + [['gr', 'ep'], GrepCommand.argParser], [['grepa', 'dd'], undefined], [['gu', 'i'], undefined], [['gv', 'im'], undefined],