I know, there is a way to run commands through plugins. For example:
view.run_command("set_setting", {"setting": "font_size", "value": 20})
But is there a way to store entire key binding inside plugin file?
Something like this? -
import sublime_plugin
class FooCommand(sublime_plugin.TextCommand):
{ "keys": ["ctrl+q"], "command": "foo" }
In short: No.
Doing so would interfere with the entire key binding system.
Sublime Text has .sublime-keymap
files which allow the keys to be set differently for each target operating system, this is so that the Human Computer Interface guidelines for each OS can be followed.
On occasion it may be desirable to use a Default.sublime-keymap
file instead of, or in addition to, the OS specific files. When that is done the key bindings defined in it will be applied to all 3 OSes, but these can be overridden if the same keys are used in one of the OS specific files.
The keymap files that can be created are:
Default.sublime-keymap (applies to all 3 OSes)
Default (Linux).sublime-keymap
Default (Windows).sublime-keymap
Default (OSX).sublime-keymap
There is no need to create .sublime-keymap
files for plugins written for your own use, if you do not want to, any plugin's key bindings can simply be placed in your user keys file Menu --> Preferences --> Key Bindings
.