Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 - Key binding for specific language?

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" }
    ] 
  }
]
like image 244
Ralph Callaway Avatar asked Jun 08 '13 18:06

Ralph Callaway


People also ask

How do I change key bindings in Sublime Text?

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

How do I select a programming language in Sublime Text?

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

What is sublime text keymap?

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.

What are key bindings?

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.


1 Answers

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.

like image 112
angerson Avatar answered Sep 26 '22 14:09

angerson