Sublime Forum

How to create key binding to python script?

#1

I’d like to bind SUPER+SHIFT+7 to the Packages/HTML/encode_html_entities.py function … instead of what I do now which is pull up the command palette and find “HTML: Encode Special Characters”.

How would I do this? I can’t find info on binding to a Python script.

Thanks in advance!

0 Likes

#2

The “HTML: Encode Special Characters” entry in the Command Palette corresponds to the “encode_html_entities” command. If you put the following in your “Default (OSX). sublime-keymap” file (or other OS-appropriate keymap file), it will bind the command to the super+shift+7 keystroke:

{ "keys": "super+shift+7"], "command": "encode_html_entities" }

Edited to add: The Python script you mentioned defined the encode_html_entities command. The command is loaded by Sublime, so you don’t have to figure out how to run the script. Sublime takes care of calling the script, whether you execute it via the Command Palette, a keystroke in a keymap, etc. Magic!

h.b.

0 Likes