4

If I want to write a few new Key Bindings for Sublime Text which should only work in LaTeX files (like typing _ or ^ after another character adds the surrounding curly brackets automatically) what do I do exactly? I don't really understand the syntax of these Key Binding files.

5

Ok. I think I figured it out. Right now it works but I haven't really tried to find cases where it behaves the wrong way. Perhaps someone can verify.

For the example I gave above, the following Key Binding works. But I am not sure if I understand it all.

[
    { "keys": ["_"], "command": "insert_snippet", "args": {"contents": "_{$1}$0"}, 
    "context":  
        [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex string.other.math"},
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
        ]
    }
]
3

If you're using snippets (i.e. .sublime-snippet extensions) you can put instructions inside scope tags in the snippet files, e.g.

<scope>text.tex.latex</scope>

That means the snippet works with only LaTeX.

The files are XML, so that's the syntax you need to learn if you're going to work with them.

.sublime-keymap files are XML too. I don't know if they work with scope in the same way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.