5

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 `backticks` to the list.


@skuroda's answer works great. On Mac OSX, go to

Sublime Text 2 > Preferences > Key Bindings - User

and paste in the text there. Make sure it is ultimately wrapped in [...] (square brackets).

4

1 回答 1

12

自动配对只是一些专门的键绑定。这应该允许您自动配对反引号。如果您想创建其他自动配对符号,它也应该作为指南。

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

只需将该代码块插入到您的用户键绑定中。

我只是将默认键绑定用作模板,因此您可能需要进一步修改一些上下文以使其完美工作。

于 2013-05-02T19:45:12.993 回答