简体   繁体   English

如何在 VSCode 中创建链接到快捷方式的自定义命令

[英]How to create a custom command linked to a shortcut in VSCode

I am looking on how to create a custom command linked to a shortcut in VSCode.我正在研究如何创建链接到 VSCode 中的快捷方式的自定义命令。 Like so:像这样:

{
    "key": "shift+enter",
    "command": "-python.execSelectionInTerminal",
    "when": "editorTextFocus && !findInputFocussed && !jupyter.ownsSelection && !notebookEditorFocused && !replaceInputFocussed && editorLangId == 'python'"
},
{
    "key": "shift+enter",
    "command": "-workbench.action.terminal.findNext",
    "when": "terminalFindFocused && terminalProcessSupported"
},
{
    "key": "shift+enter",
    "command": "-python.execSelectionInTerminal",
    "when": "terminalFindFocused && terminalProcessSupported"
},
  • Create a Task to run the current Python file创建一个任务来运行当前的 Python 文件

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "cwd": "${fileDirname}"
    }
  ]
}
  • Create a keybinding to execute this Task创建一个键绑定来执行这个任务

keybindings.json

  {
    "key": "shift+enter",
    "command": "workbench.action.tasks.runTask",
    "args": "Python: Current File",
    "when": "editorTextFocus && editorLangId=='python'"
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM