无法将命令绑定到 Sublime Text 中的空格键

Can't bind command to Spacebar in Sublime Text

我正在使用这两个绑定来自动完成:

{
"keys": ["tab"],
"command": "move",
"args": {"by": "lines", "forward": true},
"context":
    [
        { "key": "auto_complete_visible", "operator": "equal", "operand": true }
    ]
},
{
"keys": ["shift+tab"],
"command": "move",
"args": {"by": "lines", "forward": false},
"context":
    [
        { "key": "auto_complete_visible", "operator": "equal", "operand": true }
    ]
},

我想将 "commit_completion" 命令添加到 space 键:

"keys": ["space"],
"command": "commit_completion",
"context":
    [
        { "key": "auto_complete_visible", "operator": "equal", "operand": true }
    ]
},

但它不具有约束力,当我按 space 时,它会正常运行 space(它使 space xD)。我可以将它绑定到任何其他键,但不能绑定 space。我错过了什么?

space 栏没有可以这样绑定的键码;如果你想绑定一些东西到 space,你需要使用文字 space 字符:

{
  "keys": [" "],
  "command": "commit_completion",
  "context": [
    { "key": "auto_complete_visible", "operator": "equal", "operand": true }
  ]
},

这在 Sublime 控制台中可见,方法是使用 sublime.log_input(True) 打开输入日志记录,然后按下 键;唯一被记录的是角色事件,而不是按键事件。

同样重要的是要注意,您永远不想将任何内容绑定到这样的字符,除非您使用 context 来限制绑定何时应用,或者您失去了键入该字符的能力。