Sublime Forum

How to bind hotkey to any command?

#1

Sometimes I want to to bind hotkey which found in “ctrl+shift+p” or from nav menu dropdown list.
Anyone knows how to do it?

0 Likes

#2

You can select View > Show Console from the menu, or press the keyboard shortcut which defaults to Ctrl+`. In the console, enter the following command and hit enter:

sublime.log_commands(True)

Now take the action that you want to bind to a key, either from the command palette, menu, or even by pressing an existing key binding, and Sublime will show you the command (and any arguments it might need) in the console.

For example, this is what I see if I go forward and backward in a file with logging turned on:

>>> sublime.log_commands(True)
command: move {"by": "characters", "forward": true}
command: move {"by": "characters", "forward": false}

So in order to bind this to a key, the command to use is move, and the command takes arguments of by and forward that tell it what to do.

From there you can use Preferences > Key Bindings and add an appropriate binding to your customized key bindings.

The logging that this performs remains in effect until you run the same command with False as an argument or restart Sublime.

2 Likes

#3

Amazing! It works. Thank you very much!

0 Likes