From b18d18ff263760f408d39cfcb04bf2bb9e05c073 Mon Sep 17 00:00:00 2001 From: musjj <72612857+musjj@users.noreply.github.com> Date: Mon, 29 Apr 2024 02:53:52 +0700 Subject: [PATCH] Add `gB` keybinding for finding the previous match Fix: https://github.com/VSCodeVim/Vim/issues/9000 --- src/actions/commands/actions.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 196a4d7c50f..72f33f27177 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -2498,6 +2498,27 @@ class ActionTriggerHover extends BaseCommand { } } +@RegisterAction +export class ActionPreviousFindMatch extends BaseCommand { + modes = [Mode.Normal, Mode.Visual]; + keys = ['g', 'B']; + override runsOnceForEveryCursor() { + return false; + } + override runsOnceForEachCountPrefix = true; + + public override async exec(position: Position, vimState: VimState): Promise { + await vscode.commands.executeCommand('editor.action.addSelectionToPreviousFindMatch'); + vimState.cursors = getCursorsAfterSync(vimState.editor); + + // If this is the first cursor, select 1 character less + // so that only the word is selected, no extra character + vimState.cursors = vimState.cursors.map((x) => x.withNewStop(x.stop.getLeft())); + + await vimState.setCurrentMode(Mode.Visual); + } +} + /** * Multi-Cursor Command Overrides *