multiple “commands” in a single Sublime Text 2 user keymap shortcut

℡╲_俬逩灬. 提交于 2019-11-30 06:39:42

Install the "Chain of Command" plugin (works in both ST2 and ST3):
https://github.com/jisaacks/ChainOfCommand https://packagecontrol.io/packages/Chain%20of%20Command

Then you'll be able to do stuff like:

{ "keys": ["ctrl+d"],
  "context": [
    { "key": "panel_visible", "operator": "equal", "operand": true }
  ],
  "command": "chain",
  "args": {
    "commands": [
      ["hide_panel", {"cancel": true}],
      ["find_under_expand"],
    ]
  },
},

which redefines Ctrl+D so that it'll close the Find panel if it's open, then perform its normal action (Quick Add Next).

You can do any number of subcommands. Each is an array with the command name (e.g. "hide_panel") followed optionally by the arguments (e.g. {"cancel": true}).

Sara

There's a post on the Sublime Text 2 forum that includes code for a generic "run multiple commands" plugin. It will allow you to bind multiple commands to any key binding the same way you'd normally bind them to one:

  {
    "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 } }
      ]
    }
  }

Note that this is untested, and you must install the plugin provided in the post for this to work.

Alternatively, you can create a plugin for a specific set of commands following the instructions in this answer.

You can record a macro (using the Tools menu), then save it and set a keyboard shortcut to call it using

{"keys": ["super+alt+l"], "command": "run_macro_file", "args": {"file": "res://Packages/User/Example.sublime-macro"}}

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

Granted, this isn't quite what you're asking for, but may provide the same end for others with similar questions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!