【问题标题】:Executing multiple commands at a single key stroke in VS Code在 VS Code 中一次击键执行多个命令
【发布时间】:2020-02-06 07:04:02
【问题描述】:

由多个命令组成的操作示例如下。我想复制一行,复制它,然后,我需要返回上面的行并将其注释掉。目标是达到以下状态。

previousStatement();
// statementToBeMultipliedAndCommentedOut();
statementToBeMultipliedAndCommentedOut();
nextStatement();

今天,我通过这样的快速组合实现了这一目标。

ctrl+c
ctrl+v

ctrl+k+c //注释掉
down

有没有办法让组合在单个键绑定中执行这些击键?

【问题讨论】:

    标签: visual-studio-code


    【解决方案1】:

    您需要像multi-command 这样的宏扩展,这样您就可以运行一系列命令。还有其他宏扩展。使用多命令:

    在 settings.json 中:

    "multiCommand.commands": [
      {
        "command": "multiCommand.commentDown",
        "sequence": [
          "editor.action.copyLinesDownAction",
          "cursorUp",
          "editor.action.addCommentLine",
          "cursorDown"
        ]
      }
    ]
    

    这些命令可以在键盘快捷键列表中找到。在 SO 上搜索“多命令”以查看您可以使用它执行的一些操作。 (我和它没有关系。)

    在 keybindings.json 中选择一个键绑定:

    {
      "key": "ctrl+shift+/",
      "command": "extension.multiCommand.execute",
      "args": { "command": "multiCommand.commentDown" },
      "when": "editorTextFocus"
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-01
      • 2012-08-31
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      相关资源
      最近更新 更多