在括号中间按 Enter

Sublime pressing enter in the middle of a bracket

我已经从 Netbeans 转向 Sublime Text,这只是让您远离梦想设置的其中一件小事。

如果你在大括号中间按回车键,它会这样做:

$var = {
    | <-- cursor
}

但是当你在括号或括号中这样做时,它会这样做:

$var = (
    |)

$var = [
|]

我在设置花括号的键绑定中找不到。知道我怎样才能让这两个像花括号一样工作吗?提前致谢。

不确定您使用的是什么系统,但是可以在 OSX 键映射文件的第 418 行找到此键绑定。

{ "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 }
    ]
}

当您按 enter 时,它 运行 是宏文件 res://Packages/Default/Add Line in Braces.sublime-macropreceding_textfollowing_text 是一个正则表达式,定义命令何时应为 运行。

默认情况下,当光标前面有花括号,后面有花括号时,它仅设置为 运行。您可以更新正则表达式以包含括号和方括号,当光标位于它们之间时它也会 运行。

不幸的是,@Darrick Herwehe 发布的答案对我没有用,这是我尝试过的方法,并且最终像魅力一样工作。

将此添加到 用户键绑定

{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/User/Array Indent.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": "array\s*?\($", "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\)", "match_all": true }
    ]
}

然后触摸并写入内容到Packages/User/Array Indent.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} }
]