0

Is it possible to set a VS Code hotkey to input a command in the terminal? I need to input r to hot reload my flutter app. and it'll be easier if I can have a hotkey for that.

I can use ctrl+` to switch to terminal and input r myself, but I hope that there will be an easier way.

starball
  • 20,030
  • 7
  • 43
  • 238

1 Answers1

1

As @rioV8 hinted in the comments, you can do this with the workbench.action.terminal.sendSequence keybinding command.

For official documentation, see https://code.visualstudio.com/docs/terminal/advanced#_custom-sequence-keybindings.

Here's a template of what it might look like in your keybindings.json file:

{
    "key": "", // TODO put something here
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "r" }
}

Note: If the keybinding you want to use is already in use, I believe you need to explicitly disable it. You search for existing keybindings in the keybindings UI and then delete/disable them there.

Here's a bit more excerpt from the above linked docs:

This feature supports variable substitution.

The sendSequence command only works with the \u0000 format for using characters via their character code (not \x00). Read more about these hex codes and terminal sequences in the following resources:

starball
  • 20,030
  • 7
  • 43
  • 238