Search code examples
sublimetext2key-bindings

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" }
    ] 
  }
]

Solution

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