Skip to content
samob edited this page Nov 17, 2018 · 3 revisions

Keybindings

Feel free to add your own keybindings.

This is a collection keybindings, which are useful to work with LaTeX, but are not included in LaTeXTools yet.

You can copy them to your Keybindings - User file and use them.

Note that all User keybindings need to be wrapped in [ ], or there will be a parsing error.

Here are the keybindings:

    // Auto-pair escaped curly brackets
    { "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0\\\\}"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^(\\s|\\)|]|\\}|\\\\|$)", "match_all": true },
            { "key": "selector", "operand": "text.tex.latex", "match_all": true }
        ]
    },
    { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/User/Delete Left Right Twice.sublime-macro"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\\\{$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^\\\\\\}", "match_all": true },
            { "key": "selector", "operand": "text.tex.latex", "match_all": true }
        ]
    },
    // Auto-pair escaped braces
    { "keys": ["["], "command": "insert_snippet", "args": {"contents": "[$0\\\\]"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^(\\s|\\)|]|\\}|\\\\|$)", "match_all": true },
            { "key": "selector", "operand": "text.tex.latex", "match_all": true }
        ]
    },
    { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/User/Delete Left Right Twice.sublime-macro"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\\\[$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^\\\\\\]", "match_all": true },
            { "key": "selector", "operand": "text.tex.latex", "match_all": true }
        ]
    },
    // Auto-pair escaped parentheses
    { "keys": ["("], "command": "insert_snippet", "args": {"contents": "($0\\\\)"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^(\\s|\\)|]|\\}|\\\\|$)", "match_all": true },
            { "key": "selector", "operand": "text.tex.latex", "match_all": true }
        ]
    },
    { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/User/Delete Left Right Twice.sublime-macro"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\\\($", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^\\\\\\)", "match_all": true },
            { "key": "selector", "operand": "text.tex.latex", "match_all": true }
        ]
    },

    // Improve the usage of ^ and _ to create ^{} and _{}
    {
        "keys": ["^", "^"], "command": "insert_snippet", "args": {"contents": "^{${1:$SELECTION}}$0"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math, text.tex.latex string.other.math" }
        ]
    },
    {
        "keys": ["^"], "command": "insert_snippet", "args": {"contents": "^{${1:$SELECTION}}$0"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math, text.tex.latex string.other.math" },
            { "key": "selection_empty", "operator": "equal", "operand": false }
        ]
    },
    {
        "keys": ["_", "_"], "command": "insert_snippet", "args": {"contents": "_{${1:$SELECTION}}$0"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math, text.tex.latex string.other.math" }
        ]
    },
    {
        "keys": ["_"], "command": "insert_snippet", "args": {"contents": "_{${1:$SELECTION}}$0"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math, text.tex.latex string.other.math" },
            { "key": "selection_empty", "operator": "equal", "operand": false }
        ]
    },

    // Use /, / to insert \frac and *, * to insert \cdot
    {
        "keys": ["/", "/"], "command": "insert_snippet", "args": {"contents": "\\frac{${1:n}}{${2:2}}"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math, text.tex.latex string.other.math" }
        ]
    },

    {
        "keys": ["*", "*"], "command": "insert", "args": {"characters": "\\cdot"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "text.tex.latex meta.environment.math, text.tex.latex string.other.math" }
        ]
    },

Note: Some keybindings depend on a a macro. If you use the keybindings, which depend on a macro also create the a file Delete Left Right Twice.sublime-macro in your Sublime Text User directory and add the content:

[
    {
        "args": {"file": "Packages/Default/Delete Left Right.sublime-macro"},
        "command": "run_macro_file"
    },
    {
        "args": {"file": "Packages/Default/Delete Left Right.sublime-macro"},
        "command": "run_macro_file"
    }
]