是否有一些配置或插件我可以使用,当它们匹配时,会在括号内添加空格。下面是我想解释的一个例子。
if (^) // ^ represents cursor position
if ( ^ ) // Where I want the cursor to be positioned.
答案1
您可以编辑自动配对功能。我将以下内容从“键绑定 - 默认”复制到“键绑定 - 用户”。在值中添加空格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 }
]
},
编辑
为了使键绑定语法特定,在值的底部添加一行context
。您必须找到语法scopeName
。例如 html 是text.html
而 sass 是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" }
]
},