8

In the replace mode of vscode:

enter image description here

The hotkeys of 'go to next match' and 'replace' are both enter.

I want to selectively replace some words. For example, in the lower part of the image: I want to rename hidden_dim' but not hidden_dim_in`.

Hitting the key enter will repeatedly do either 'go to next match' or 'replace'. How could I set different hotkeys for these two functions?

Mark
  • 143,421
  • 24
  • 428
  • 436
zheyuanWang
  • 1,158
  • 2
  • 16
  • 30

3 Answers3

6

Inspired by @amordo's answer, I find an easier way to "go to next match" while replacing words in vscode:

F3

The F3-key is the default setting of vscode for finding next, which works properly during replacing.

enter image description here

Ps. the Shift + Enter short cut, doesn't help in this case. It will add a new line.enter image description here

zheyuanWang
  • 1,158
  • 2
  • 16
  • 30
2

I've added a new shortcut to keybindings.json Command Palette -> Preferences: Open Keyboard Shortcuts (JSON):

{
    "key": "shift+cmd+enter",
    "command": "editor.action.nextMatchFindAction",
    "when": "editorFocus && replaceInputFocussed"
}

Another way is to Add Keybinding... based on 'go to next match' (Find Next) shortcut in Preferences: Open Keyboard Shortcuts and change it via UI. enter image description here

Now using a new shortcut with replace window focused you go to the next match; press enter to replace that.enter image description here

amordo
  • 449
  • 5
  • 15
0

I've found a really simple way of doing this with no customization. When the focus is on the find text box, hitting enter will go to the next match without applying any change however, when focus is in the replace text box hitting enter will make the change and go to the next match. It is possible to switch focus between the two text boxes using tab and shift + tab.

Rory Fahy
  • 11
  • 2
  • He asked for a hotkey configuration not an alternative way actually – Mushfiqur Rahman Abir Jan 23 '23 at 15:08
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 23 '23 at 15:08