在 VS Code 中一次击键执行多个命令 [英] Executing multiple commands at a single key stroke in VS Code

查看:32
本文介绍了在 VS Code 中一次击键执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

One example of an operation consisting of multiple commands would be the following. I want to copy a line, making a duplicate of it, then, I need to return the the upper line and comment it out. The aim is to reach the following state.

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

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

Today, I achieve that by a quick combination like this.

ctrl+c
ctrl+v
向上
ctrl+k+c//注释掉

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

Is there a way to make a combo executing those keystrokes in a single key binding?

推荐答案

您需要一个宏扩展,例如 多命令,因此您可以运行一系列命令.还有其他宏扩展.使用多命令:

You need a macro extension like multi-command so you can run a sequence of commands. There are other macro extensions out there. Using multi-command:

在 settings.json 中:

In settings.json:

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

可以在键盘快捷键列表中找到这些命令.在 SO 上搜索多命令"以查看您可以使用它做的一些事情.(我与它没有任何关系.)

The commands can be found in the Keyboard Shortcuts listing. Search on SO for "multi-command" to see some of things you can do with it. (I have no connection to it.)

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

Choose a keybinding in keybindings.json:

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

这篇关于在 VS Code 中一次击键执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆