+11
Key binding context to only react on e.g. Python code
What do I have to put into the context list to only have my key binding react on scope source.python?
I want to bind the same key to somewhat similar scripts but for different languages (e.g. Python, PHP, XML, Bash).
I want to bind the same key to somewhat similar scripts but for different languages (e.g. Python, PHP, XML, Bash).
Сервис поддержки клиентов работает на платформе UserEcho
{ "key": "selector", "operator": "equal", "operand": "source.python" }
{ "keys": ["ctrl+alt+shift+t"], "command": "python_tidy", "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.python" }
]
},
This an example from a file I currently use:
[
{ "keys": ["alt+o"], "command": "switch_file", "args": {"extensions": ["pas", "dfm"]}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.pascal" }
]
},
{ "keys": ["ctrl+shift+r"], "command": "delphi_switch_head_body", "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.pascal" }
]
}
]
Do you mean that the keymap is always called whatever the current file edited ?
Are you sure the keymap file is loaded ?
Are you sure you don't redefined the keymap somewhere else ? (try to call somtehing else)
In my user defined keybindings I have:
{ "keys": ["ctrl+alt+shift+t"], "command": "python_tidy", "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.python" }
]
},
{ "keys": ["ctrl+alt+shift+t"], "command": "perl_tidy", "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.perl" }
]
},
These are not bound anywhere else.
When hitting save I can see that sublime reloads my two keymap files.
So here's what I discovered so far:
1. After starting sublime, I can go into any file and hit the key combo to invoke python_tidy - regardless of the file type/ext/syntax.
2. I add a prefix to the commands like "xxx" so that they won't work anymore and hit save.
3. When hitting the combo I get a strange letter in the view. Sounds deactivated. The console throws a proper error message.
4. I remove the prefix from the commands and hit save.
5. When hitting the combo they react as intended and not in every file (e.g. python-file -> python_tidy, perl-file -> perl_tidy, anywhere else -> strange letter).
Only Jon or someone with OSX could help you.
Good luck.
{ "keys": ["ctrl+alt+shift+t"], "command": "", "context":
[
{ "key": "selector", "operator": "not_equal", "operand": "source.python" },
{ "key": "selector", "operator": "not_equal", "operand": "source.perl" }
]
},
This effectively disables the binding when not in python or perl code.
Jon, should I open a bug entry for this?
I am facing the same bug. This keymap is active on all types of files, so the context is not working.
{ "keys": ["super+shift+x"], "command": "something_cool", "context" : [ { "key": "selector", "operator": "equal", "operand": "source.ruby", "match_all": true } ]}
I'm experiencing the same issue (ST 2.0.1 build 2217 on 32-bit Win7). I created a keybinding for auto-doubling percent signs (%) in AutoHotkey and dos batch scripts. However, it shows up in most/all files. Here's my code: