How to search highlighted word immediately via F3 without first pressing CTRL-F?

Viewed 38

In VS Code, on Windows, is there a setting (I looked but couldn't find) that will let me just press F3 to search the current highlighted word without first having to press CTRL-F ?

It's incredibly convenient to just double-click a word then F3 to search it. Other editors (like UltraEdit) do this; hoping VS Code has this ability. Perhaps an extension?

1 Answers

Edit: Just after I wrote this, the multi-command extension was updated! For a simple macro like this, you no longer need to have the settings.json entry mentioned below. This keybinding is enough:

  {
    "key": "F3",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "actions.find",
        "editor.action.nextMatchFindAction"
      ]
    },
    "when": "editorTextFocus"
  }

Previous answer I'll probably delete shortly (as the extension was updated shortly after I wrote the following)::

I don't think there is a direct way to do that but you could make a macro that seems to work well. Using multi-command:

In settings.json:

"multiCommand.commands": [

  {
    "command": "multiCommand.findNext",
    "sequence": [
      "actions.find",
      "editor.action.nextMatchFindAction"
    ]
  }
}

and a keybinding (in keybindings.json) to trigger that:

{
  "key": "F3",               // whatever keybinding you wish
  "command": "extension.multiCommand.execute",
  "args": {
    "command": "multiCommand.findNext"
  },
  "when": "editorTextFocus"
}

You don't need to double-click the word first, just have the cursor in it. If you want to require that the word be selected, use this when context instead:

"when": "editorTextFocus && editorHasSelection"

It does need to use your Find widget so it will replace whatever value may have been in it before.

Demo not requiring a selection, just current word:

find next macro demo

It is actually a nice little functionality boost - I think I will start to use this (with a keybinding where I don't have to hit a function key though).

Related