Modify auto_match of quotes, adding an additional quoting character to Sublime Text 2

前端 未结 1 1736
借酒劲吻你
借酒劲吻你 2021-01-01 02:10

Sublime Text 2 very helpfully closes all of my quotes.
Is it possible to modify which characters it does this with?

For example, if I would like to add `backtic

相关标签:
1条回答
  • 2021-01-01 02:54

    The auto pairing is simply a few specialized keybindings. This should allow you to auto pair backticks. It should also serve as a guide for if you want to create other auto paired symbols.

    { "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": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true }
        ]
    },
    { "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
        ]
    },
    { "keys": ["`"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
        [
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
        ]
    },
    { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Left Right.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 }
        ]
    }
    

    Simply insert that code block into your user key bindings.

    I just used the default keybinding as a template, so you may need to further modify some of the context to get it to work perfectly.

    0 讨论(0)
提交回复
热议问题