【问题标题】:VScode: hotkey for execute last terminal command while editing?VScode:编辑时执行最后一个终端命令的热键?
【发布时间】:2020-09-29 18:42:19
【问题描述】:

如何在 VScode 中创建以下热键:

  1. 在编辑文件时(文本文件中的光标/焦点),执行最后一个终端命令
  2. 将光标/焦点返回到文本文件中的位置,以便我可以无缝地继续编码

这用于调试代码并通过终端有效地运行代码

【问题讨论】:

    标签: visual-studio-code terminal editor shortcut hotkeys


    【解决方案1】:

    我简化了我之前的答案。设置中不需要任何内容​​。

    您将需要像multi-command 这样的宏扩展。使用多命令,进行此键绑定:

    {
        "key": "alt+x",     // whatever keybinding you want
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                {
                    "command": "workbench.action.terminal.sendSequence",
                             // send an uparrow to the terminal shell
                    "args": {"text": "\u001b[A\u000D"}, 
                },
                "workbench.action.focusActiveEditorGroup",  // return focus to last active editor
            ]
        },
         // if you want this to work only when focus is in an editor
        "when": "editorFocus" 
    }
    

    有关上述sendSequence 命令部分的说明,请参阅https://stackoverflow.com/a/55336498/836330(进行键绑定以运行上一个或最后一个 shell 命令)。

    【讨论】:

      【解决方案2】:

      您还可以在 Mark 命令序列的开头添加一些其他有用的命令!

          {
              "key": "alt+x",
              "command": "extension.multiCommand.execute",
              "args": {
                  "sequence": [
                      "workbench.action.files.saveAll",
                      "workbench.action.terminal.scrollToBottom",
                      {
                          "command": "workbench.action.terminal.sendSequence",
                          "args": {"text": "\u001b[A\u000D"},
                      },
                      "workbench.action.focusActiveEditorGroup",
                  ]
              },
              "when": "editorFocus"
          }
      

      【讨论】:

      • 我想你不能因为缺乏声誉而仅仅评论马克的答案......无论如何,添加一些描述来解释你如何以及为什么改进原始答案,这将使你的答案更有价值
      猜你喜欢
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2015-05-21
      • 2020-08-27
      • 2022-11-09
      • 2021-01-31
      相关资源
      最近更新 更多