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.
2 Answers
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 }
]
}
]
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.