Sublime Text 键绑定 - 当按下 space 栏时,应用 space 位于括号之间

Sublime Text Key Binding - app space between parentheses when press the space bar

我添加了一个键绑定,当我在 SublimeText 中按“(”时,它会将选择器置于括号之间。

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

但是,我想创建一个键绑定,当我按下 space 栏并且我在括号之间时,它会将 (|) 变成 (|)。

有什么想法吗?

对于这样的事情,您需要如下所示的键绑定:

{
    "keys": [" "],
    "command": "insert_snippet",
    "args": {
        "contents": " [=10=] "
    },
    "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 }
    ],
}

insert_snippet 命令插入一个片段,其中包含两个 space 字符,光标位于它们之间,而 context 条目仅在没有选择时才激活绑定,光标前的文本以 ( 结尾,光标后的文本以 ).

开头

正如所写,这在这种情况下将始终处于活动状态,但如果需要,您也可以在此处取消注释第一个上下文条目,这进一步限制了此绑定仅在 auto_match_enabled 设置打开时处于活动状态。这将使它仅在输入单个 ( 字符会自动插入配对字符的情况下激活。