Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Key binding. How to run a external script (external command/program) in sublime text 2 when pressing a key?

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?

like image 789
GarouDan Avatar asked May 05 '12 20:05

GarouDan


People also ask

What is the shortcut key to run a program in sublime?

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

How do I change the key bindings in Sublime Text?

Go to "Preferences" -> "Key Bindings"

How add key bindings sublime?

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+`.

What are key bindings?

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.


1 Answers

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.)

like image 50
GarouDan Avatar answered Oct 04 '22 05:10

GarouDan