【问题标题】:Sublime Text Key Binding - app space between parentheses when press the space barSublime Text Key Binding - 按空格键时括号之间的应用空间
【发布时间】:2018-11-20 18:36:39
【问题描述】:

我添加了一个键绑定,当我在 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 }
  ]
},

但是,我想创建一个键绑定,当我按下空格键并且我位于括号之间时,它会将 (|) 转换为 (|)。

有什么想法吗?

【问题讨论】:

    标签: key sublimetext3 key-bindings


    【解决方案1】:

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

    {
        "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": "^\\)", "match_all": true }
        ],
    }
    

    insert_snippet 命令插入一个包含两个空格字符的 sn-p,光标在它们之间居中,而 context 条目仅在没有选择时才激活绑定,光标之前的文本以(,光标后面的文本以)开头。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多