I would like to run a external python script (or external command/program) when I press a key on Sublime Text 2.
How can I do this?
The shortcut key for this purpose is Ctrl+Shift+P for Windows and Cmd+Shift+P for Mac.
Go to "Preferences" -> "Key Bindings"
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+`.
A key binding is an association between a physical key on a keyboard and a parameter. A parameter can have any number of key bindings associated with it, and a particular key binding can control any number of parameters. Key bindings detects individual keys being pressed.
Here is a solution:
Preferences->Key Bindings - User and put this in the file (overriding the [
,]
inside):
[
{ "keys": ["<your shortucut>"], "command": "exec", "args": { "cmd": ["<path to your script>"]} }
]
Where <your shortcut>
as the name says is the shortcut (examples: F1, ctrl+shift+F1, etc.) and <path to your command>
is the location of your command (examples: echo
, /home/user/scripts/my_script.py
, ls
, etc.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With