Bind terminal commands to VSCode keyboard shortcuts

Do you want to bind a terminal command to VSCode keyboard shortcut?

A software developer often has to run the same command over and over again, for example, to run a Node.js live development server.

In this case, opening Terminal a couple of times a day becomes a boring task. What if we can bind a keyboard shortcut to the command and run it right inside VSCode?

This article is going to show you how to run terminal commands from inside VSCode quickly using a keyboard shortcut.

Suppose we had Nodejs and Live Server installed, we want to run live-server --port=3000 --browser=Firefox to run a local dev server and open it with Firefox.

Next thing you need to open Command Palette and find Preferences: Open Keyboard Shortcuts (JSON).

Add the following lines to the file, inside the brackets.

{
  "key": "shift + l",
  "command": "workbench.action.terminal.sendSequence",
  "args": {
    "text": "live-server --port=3000 --browser=Firefox\u000D"
  }
}

In the snippets above, we bind Shift + L to the workbench.action.terminal.sendSequence action with our command as the argument.

Note that we added \u000D to the end of the terminal command, which translates to a newline character (\n), equivalent to a Enter key press into VSCode integrated terminal.

Follow the same process, you can bind any other keyboard shortcuts to terminal commands.

We hope that you've learned how to quickly run a terminal command from VSCode using a key combination. Here's a few of our other VSCode guides if you're interested.

Click to rate this post!
[Total: 18 Average: 5]

Leave a Comment