Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple "commands" in a single Sublime Text 2 user keymap shortcut

Tags:

Is there a way to have multiple "commands" associated with one shortcut?

I have these two shortcuts. First shortcut makes the window on the left larger than the right one (in a 2 column view) and the next shortcut puts the focus on the first window. I tend to forget one or the other shortcut when coding quickly.

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

This question makes me sound like i'm lazy but i'd like to think of it as being efficient.

Any advice or suggestions, please?

like image 742
Satans Sidekick Avatar asked Nov 14 '12 22:11

Satans Sidekick


People also ask

What does ctrl d do in Sublime Text?

Ctrl + D in SublimeText is "Quick Add Next." This appears to be equivalent to Ctrl + B in Brackets, which is "Add next match to Selection" on the Find menu.

How do I add shortcuts to Sublime Text?

You can use the shortcut key Ctrl+Shift+N on Windows and Cmd+Shift+N for Mac to create a new window on Sublime Text editor.

What is the shortcut key for Sublime Text?

The shortcut key for this purpose is Ctrl+Shift+P for Windows and Cmd+Shift+P for Mac.

How do I change key bindings in Sublime Text?

Users can customize their key bindings by creating a file named Default. sublime-keymap in their Packages/User/ directory. For example, the following will create a key binding to show unsaved changes, if any exist, via Ctrl+Shift+`.


1 Answers

As of Sublime Text 4 (build 4104, 3 May 2021) you can use the built in chain command.

In older versions (ST2 or ST3) you needed to install the Chain of Command plugin (GitHub).

Both have the same syntax, allowing you write keybindings etc that perform multiple actions, e.g.:

{ "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}). The unofficial/incomplete documentation of available commands and their arguments may be helpful.

like image 102
John Mellor Avatar answered Sep 21 '22 18:09

John Mellor