Sublime Text 3 Reindent在PHP中使用正确的数组括号

Gol*_*bby 6 sublimetext sublimetext2 sublimetext3

我有这样一个问题,

但在上面的链接回答没有帮助我.我习惯于在编码时重新整理整个文件,我非常喜欢Sublime Text.但这个错误让我很生气.所以我需要使用快捷方式重新整理整个PHP文件,并且不要错误缩进.

这就是我需要的:

这就是它的作用:

Ели*_* Й. -1

我正在使用 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 }
  ]
}
Run Code Online (Sandbox Code Playgroud)

这里要注意的是,这个设置文件是一个JSON-Array,上面的代码必须写在括号中:

[
  // Copy above configuration here
]
Run Code Online (Sandbox Code Playgroud)

如果您的设置文件中已有一些键绑定,则必须用逗号分隔它们:

[
  {
    // Some existing keybindings
  },
  // Copy above configuration here
]
Run Code Online (Sandbox Code Playgroud)

然后,您应该在 Sublime Text 3 的用户文件夹中创建一个宏文件。在哪里可以找到该文件夹​​取决于您使用的操作系统。例如,在 Ubuntu 上是:

〜/.config/sublime-text-3/Packages/用户

在此文件夹中创建一个新文件,并命名(注意大小写和空格):

在 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} }
]
Run Code Online (Sandbox Code Playgroud)

这一定有用,对我有用。