说明
我刚刚自己想出了如何做你清单上的一件事。
我修改了当您按下"enter" 键时运行的正则表达式。
旧的正则表达式检查了这个"operand": "\\{$" 和这个"operand": "^\\}"
我添加了or 使用管道| 检查以同样方式检查[ 和(:"operand": "\\{$|\\[$|\\($" 和"operand": "^\\}|^\\]|^\\)"
方向
导航到首选项>键绑定 - 用户
就个人而言,我通过将简短的绑定放在顶部,将较大的块绑定/关注点放在底部来保持这个文件的组织。我认为以下是一个更大的块。
将此新代码粘贴到文件中:
// Auto-insert line and indent on square bracket and bracket (parenthesis)
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "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 }
]
},
{ "keys": ["shift+enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "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 }
]
},
几点说明:
- 正如我所说,我的代码为括号执行此操作。 (Sublime 将括号称为“方括号”,区别于“方括号”和“大括号”。)
- 如果您不希望它在括号上工作,请将第一个“操作数”检查更改为:
"operand": "\\{$|\\[$",并将下一行的“操作数”检查更改为:"operand": "^\\}|^\\]"
- 最后,我猜 Sublime 无论如何都能正确解析它,但我在右大括号的末尾有一个逗号
,,这会假设您后面还有一些键绑定。如果它是文件末尾右方括号之前的最后一个绑定,则应删除逗号。
另外,至少在 Sublime Text 3 中,您关于 <div> 缩进的问题已得到修复。