Question
What's the proper way to create a key binding for a specific language?
Background
I'd like to insert a semi-colon after each line automatically when working on java files. I've created a macro to accomplish and have been able to bind it to super+enter
. Now I'd like to scope the key binding to just java files. What am I doing wrong?
[
{
"keys": ["super+enter"], "command": "run_macro_file",
"args": {"file": "Packages/User/Add Line SemiColon.sublime-macro"},
"context": [
{ "key": "selector", "operator": "equals", "operand": "source.java" }
]
}
]
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+`.
Click the Plain Text label at the bottom right of the window and select your language. Alternatively, select your language in the menu at View » Syntax, or open your command palette ( Ctrl Shift P ) and type ssjava (equals to Set Syntax: Java ).
Advertisements. Key bindings in Sublime Text helps a user to process and map the sequences of key presses to actions. They are defined in the JSON format and are stored in . sublime-keymap files. For better integration, it is important to keep separate key map files for Linux, OSX and Windows.
key binding (plural key bindings) (computing) A key, or key combination, which, when pressed, causes something to happen. I changed the key binding for pause to the Escape key.
You're going to love this—the comparison operator that you're looking for isn't equals
, it's equal
:
Context Operators
equal
,not_equal
— Test for equality.
regex_match
,not_regex_match
— Match against a regular expression.
regex_contains
,not_regex_contains
— Match against a regular expression (containment).
Change that, and you shouldn't have any more trouble.
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