Skip to content

Commit

Permalink
Simple :grep using vscode search
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahtinen committed Dec 4, 2024
1 parent 715fca7 commit dcb0983
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/cmd_line/commands/grep.ts
Original file line number Diff line number Diff line change
@@ -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<GrepCommand> = 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<void> {
vscode.commands.executeCommand('workbench.action.findInFiles', {
query: this.pattern,
triggerSearch: true,
});
}
}
3 changes: 2 additions & 1 deletion src/vimscript/exCommandParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExCommand>;

Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit dcb0983

Please sign in to comment.