Create a new file .vscode/tasks.json
:
{
"tasks": [
{
"type": "shell",
"label": "run project",
"command": "make",
"args": [
"run"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Custom command to run project"
},
],
"version": "2.0.0"
}
The name of the task is run project
, this is relevant for the keybindings later. In this case the command make run
is executed in the root of the workspace (${workspaceFolder}
). The problemMatcher
allows for showing errors inside the source files, here we read the output as gcc
warnings/errors. You could use other existing matchers like $tsc
for typescript or write your own matcher using Regex (See VS Code documentation for details).
Open the Keyboard Shortcuts JSON file by typing > Preferences Open Keyboard Shortcuts (JSON)
into the search bar.
Then add the following key configuration:
[
{
"key": "f6",
"command": "workbench.action.tasks.runTask",
"args": "run project"
}
]
Here we bind the task run project
to the key F6
. If you used a different name in tasks.json
above you have to change the args accordingly.
The command workbench.action.tasks.runTask
executes the task specified in the first argument.