Reputation: 65
Currently Ctrl
+Enter
runs code from the main directory.
I want to change this shortcut to run code from the integrated terminal directly.
My current workflow is:
file.py
file.py
Is there way to change the shortcut above to use the workflow instead.
Upvotes: 0
Views: 128
Reputation: 113
If you want, you can make a task and assign a keybinding to it.
If you don't have a tasks.json
file, go to the Command Palette (Ctrl+Shift+P if that hasn't been remapped), and enter Tasks: Configure Tasks
, Configure tasks.json file from template
, and Others
. You should now have a tasks.json
file.
The tasks
key is an array, and you can insert an object there. For your case, you can have
{
"label": "Run python file",
"type": "shell",
"command": "py",
"args": ["${file}"],
"group": {
"kind": "build",
"isDefault": false
}
}
To have the keybinding, go to Keyboard Shortcuts (Settings > Keyboard Shortcuts [Ctrl + K Ctrl + S if this hasn't been remapped]) and click Open Keyboard Shortcuts (JSON)
.
There, define your own keybinding. For now, I choose F5F5, and we'll add this object.
{
"key": "f5 f5",
"command": "workbench.action.tasks.runTask",
"when": "editorLangId == python",
"args": "Run python file"
}
To explain, when we press F5 followed by F5 and we are an editor identified as a Python file, VSCode will run the command workbench.action.tasks.runTask
. To choose which task VSCode will run, we'll provide the name of the task through the args
key which is Run python file
.
Upvotes: 1