单个Sublime Text 2用户键映射快捷方式中的多个"命令"

Sat*_*ick 17 keyboard-shortcuts keymapping sublimetext2

有没有办法让多个"命令"与一个快捷方式相关联?

我有这两个捷径.第一个快捷方式使左侧窗口大于右侧窗口(在2列视图中),下一个快捷方式将焦点放在第一个窗口上.在快速编码时,我倾向于忘记一个或另一个快捷方式.

{
    "keys": ["super+alt+left"],
    "command": "set_layout",
    "args":
    {
        "cols": [0.0, 0.66, 1.0],
        "rows": [0.0, 1.0],
        "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
    }
},
{ "keys": ["ctrl+alt+left"], "command": "focus_group", "args": { "group": 0 } }
Run Code Online (Sandbox Code Playgroud)

这个问题让我觉得我很懒,但我想把它看成是有效率的.

有什么建议或意见吗?

Joh*_*lor 29

安装"命令链"插件(适用于ST2和ST3):
https ://github.com/jisaacks/ChainOfCommand https://packagecontrol.io/packages/Chain%20of%20Command

然后你就可以做到这样的事情:

{ "keys": ["ctrl+d"],
  "context": [
    { "key": "panel_visible", "operator": "equal", "operand": true }
  ],
  "command": "chain",
  "args": {
    "commands": [
      ["hide_panel", {"cancel": true}],
      ["find_under_expand"],
    ]
  },
},
Run Code Online (Sandbox Code Playgroud)

重新定义Ctrl + D,以便在它打开时关闭"查找"面板,然后执行其正常操作(快速添加下一个).

您可以执行任意数量的子命令.每个都是一个带有命令名称的数组(例如"hide_panel"),后跟可选的参数(例如{"cancel": true}).


Sar*_*ara 14

Sublime Text 2论坛上有一篇文章,其中包含通用"运行多个命令"插件的代码.它允许您将多个命令绑定到任何键绑定,就像您通常将它们绑定到一个一样:

  {
    "keys": ["super+alt+left"],
    "command": "run_multiple_commands",
    "args": {
      "commands": [
        { "command": "set_layout", "args": { "cols": [0.0, 0.66, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] } },
        { "command": "focus_group", "args": { "group": 0 } }
      ]
    }
  }
Run Code Online (Sandbox Code Playgroud)

请注意,这是未经测试的,您必须安装帖子中提供的插件才能使用.

或者,您可以按照本答案中的说明为特定命令集创建插件.


Jon*_*Jon 6

您可以录制宏(使用"工具"菜单),然后保存它并设置键盘快捷键以使用它来调用它

{"keys": ["super+alt+l"], "command": "run_macro_file", "args": {"file": "res://Packages/User/Example.sublime-macro"}}
Run Code Online (Sandbox Code Playgroud)

http://docs.sublimetext.info/en/latest/extensibility/macros.html

当然,这并不是你所要求的,但可能会为有类似问题的其他人提供同样的结果.