How can I run a custom task (different from test or build) from a keychord shortcut in VSCode?

前端 未结 3 2095
醉梦人生
醉梦人生 2020-12-19 11:44

I know I can assign a keychord to 2 standard tasks: build and test in VSCode. I need to do the same with a custom task. How can I do it?

相关标签:
3条回答
  • 2020-12-19 12:26

    Use runTask with args.

    {
        "key": "shift+cmd+t",
        "command": "workbench.action.tasks.runTask",
        "args": "The name of your task"
    }
    
    0 讨论(0)
  • 2020-12-19 12:39

    You can't currently. Here is the github issue with the feature request. Looks like it keeps getting pushed to 'the next' release.

    0 讨论(0)
  • 2020-12-19 12:49

    As the other answer says, you currently cannot. But until it is fixed, there is a ...

    Workaround using AutoHotKey:

    Run fixed command line using keyboard shortcut:

    ^!1::Run mytask.exe myfile.txt
    

    The above one launches command line mytask.exe myfile.txt on pressing Ctrl+Alt+1.

    If you want to limit scope of the shortcut from global to VSCode only, add #IfWinActive directive before that line.

    Of course, you can also expand the macro to determine the file dynamically (or from user input) but I wanted to show you some minimum example which is a way to go.

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