在 Sublime Text 2 中的括号之间自动插入一个空格

Log*_*ley 7 sublime-text-2

是否有一些我可以使用的配置或插件,当它们匹配时会在括号内添加空格。这是我试图解释的一个例子。

if (^) // ^ represents cursor position
if ( ^ ) // Where I want the cursor to be positioned.
Run Code Online (Sandbox Code Playgroud)

d_r*_*ail 8

您可以编辑自动配对功能。我将以下内容从“键绑定 - 默认”复制到“键绑定 - 用户”中。在contents值中添加空格。您可以对方括号和大括号执行类似的操作。第一个设置将其设置为正常使用。当您突出显示文本时,第二个设置它。

// Auto-pair brackets
{ "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 }
  ]
},
Run Code Online (Sandbox Code Playgroud)

编辑 要使键绑定语法特定,请在context值的底部添加一行。您必须找到语法的scopeName. 例如 html istext.html和 sass is source.sass

{ "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 },
    { "key": "selector", "operator": "equal", "operand": "source.sass" }
  ]
},
Run Code Online (Sandbox Code Playgroud)