2015-02-09 39 views

回答

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": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|$)", "match_all": true } 
    ] 
}, 
{ "keys": ["{"], "command": "wrap_block", "args": {"begin": "{", "end": "}"}, "context": 
    [ 
     { "key": "indented_block", "match_all": true }, 
     { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true }, 
     { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }, 
     { "key": "following_text", "operator": "regex_match", "operand": "^$", "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 } 
    ] 
}, 

注意,通过使用单个字符作为键绑定,你拦截按键,它不会在显示缓冲。如果你想把字符发送到缓冲区,你需要把它放在那里作为你的命令的一部分。

您可以在示例中看到。这两个insert_snippet命令包裹的任何参数与大括号:"contents": "{$0}"wrap_block命令发送大括号的开始和结束ARGS:"args": {"begin": "{", "end": "}"}

+0

我试过了,它执行我的命令,但'}'心不是在编辑器中 – Jon 2015-02-09 20:57:28

+0

@乔恩我已经添加了一些额外的解释 – 2015-02-09 21:10:00

相关问题