我正在使用 Sublime Text 3,可以使用该页面上的说明解决此问题。我在此处复制相同的说明以供参考,我将尝试提供一些提示以找出它不适合您的原因。
首先,我在我的键绑定设置中添加了这些行(首选项 -> 键绑定 - 用户):
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "Packages/User/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 }
]
}
这里一定要注意,这个设置文件是一个JSON-Array,上面的代码一定要写在括号里:
[
// Copy above configuration here
]
如果您的设置文件中已经有一些键绑定,则必须用逗号分隔它们:
[
{
// Some existing keybindings
},
// Copy above configuration here
]
然后你应该在你的用户文件夹中为 Sublime Text 3 创建一个宏文件。在哪里可以找到这个文件夹取决于你使用的操作系统。例如,在 Ubuntu 上是:
~/.config/sublime-text-3/Packages/User
在这个文件夹下新建一个文件,并命名(注意大小写和空格):
在 Braces.sublime-macro 中添加行
在此文件中,复制以下脚本并保存:
[
{"command": "insert", "args": {"characters": "\n\n"} },
{"command": "left_delete", "args": null},
{"command": "move", "args": {"by": "lines", "forward": false} },
{"command": "move_to", "args": {"to": "hardeol", "extend": false} },
{"command": "reindent", "args": {"single_line": true} }
]
这一定有效,它对我有用。