ssxrgio
ssxrgio

Reputation: 23

Run files in terminal from VS Code

Is there any VS Code shorcut that lets you run a file in the Windows terminal without writing the path of the file directly into the terminal?

Thanks in advance.

Upvotes: 2

Views: 722

Answers (2)

Mark
Mark

Reputation: 180641

Try

  {
    "key": "ctrl+shift+t",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "node '${file}'\u000D" }
  }

With whatever keybinding you wish. See Release notes: sendSequence and variables.

With vscode v1.32 you can sendSequence to the terminal using variables like ${file}, which is the current file. If you want some other path there, replace ${file} with your pathname in the keybinding above.

In the above keybinding I just added node - replace that with whatever you need to run python files in the terminal. Like whatever your setting is: "c:/python27/python.exe" from "python.pythonPath": "c:/python27/python.exe"

The \u000D is a return so it runs automatically.

I added 's around the ${file} variable in case your file path has spaces in it,

like c:Users\Some Directory\fileToRun

Upvotes: 3

El_Loco
El_Loco

Reputation: 1866

If I understand your question I think you can look into the answer here and here. I guess you have to change your task.json accordingly.

Upvotes: 0

Related Questions