Run files in terminal from VS Code

2020-04-24 17:11发布

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.

2条回答
家丑人穷心不美
2楼-- · 2020-04-24 17:17

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

查看更多
爷的心禁止访问
3楼-- · 2020-04-24 17:31

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.

查看更多
登录 后发表回答