Run files in terminal from VS Code

前端 未结 2 684
[愿得一人]
[愿得一人] 2021-01-22 06:55

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条回答
  • 2021-01-22 07: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.

    0 讨论(0)
  • 2021-01-22 07:40

    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

    0 讨论(0)
提交回复
热议问题