Answer the question
In order to leave comments, you need to log in
How to bind different commands to a hotkey depending on the syntax?
In my case, it is necessary that if I press ctrl + q in the js file, then the console.log macro is executed, and in another type of document, something else happens
{
"keys": ["ctrl+q"],
"command": "run_macro_file",
"args": {"file": "Packages/User/console.sublime-macro",
"syntax": "Packages/HTML/HTML.sublime-settings", // * ???
}
Answer the question
In order to leave comments, you need to log in
args are command arguments and you need context
sublimetext.info/docs/en/reference/key_bindings.html
https://forum.sublimetext.com/t/per-syntax-key-bin...
Specifically selector is scope , which just defines the language
Here is an example for HTML:
{
"keys": ["ctrl+shift+enter"],
"command": "insert_snippet",
"args" : {
"contents": "<br/>"
},
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.html" }
]
},
[
{
"keys": ["ctrl+k", "alt+k"],
"command": "set_layout",
"args":
{
"cols": [0.0, 1.0],
"rows": [0.0, 1.0],
"cells":
},
"context": [
{ "key": "selector", "operator": "equal", "operand": "source.c++" }
]
}
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question