【问题标题】:how to align text to specific character in phpstorm or webstorm?如何将文本与 phpstorm 或 webstorm 中的特定字符对齐?
【发布时间】:2013-06-21 07:17:59
【问题描述】:

我有这段文字

$test1 = 'testing1';
$test1test1 = 'testing1';
$test1test1test1 = 'testing1';
$test1 = 'testing1';

我想像这样使用制表符对齐它,

$test1           = 'testing1';
$test1test1      = 'testing1';
$test1test1test1 = 'testing1';
$test1           = 'testing1';

有没有办法在 phpstorm 或 webstorm 中做到这一点?

【问题讨论】:

标签: php text alignment phpstorm webstorm


【解决方案1】:

Cmd+Alt+L(在 Mac 中)或 Ctrl+Alt+L(Win)和 PHP Storm 将根据您在设置中的代码样式来格式化代码。要设置此代码样式,请执行以下操作: 文件 -> 设置 -> 代码样式 -> PHP(在此处选择您的语言) -> 其他 -> 对齐键值对 - 标记为选中。然后按重新格式化代码 (Ctrl+Alt+L),瞧。你会得到代码,你在上面写的样式。

【讨论】:

  • 它不适用于 phpstorm 6.0.3 版本,尽管我也为此进行了设置。你能帮我吗
  • 我在 Win7 上使用 PhpStorm 6.0.3,我在 ALT+F8 上有“代码重新格式化”。这可能取决于您使用的操作系统和键盘映射设置。单击菜单中的 代码 -> 重新格式化代码 - 您还应该通过 重新格式化代码 菜单选项看到您的键盘快捷键。
  • 请注意,还有一个对齐键 => 值对的设置(至少在 PHPStorm 6.0.3 中)。很好的答案谢谢。
  • JavaScript 也可以这样吗?我在那里找不到选项...:/
  • 在 phpStorm 9.x 中“对齐列中的字段”。
【解决方案2】:

我在 PhpStorm 8.0.2 中找到了它:

设置 -> 编辑器 -> 代码样式 -> PHP -> 换行和大括号 -> 对齐连续赋值

【讨论】:

  • 提供的答案可能是正确的,但@Sam 提供的答案也是必不可少的。
  • 我正在使用 PHPStorm 2021.2.3,Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> match expression -> Align 'match' arm bodies
【解决方案3】:

phpstorm 8 中的格式化选项

设置 > 代码样式 > php > 换行和大括号

检查两个选项 对齐选项中的字段和对齐常量

现在你可以得到你想要的! :)

来源Jetbrains Blog

【讨论】:

  • “赋值语句>对齐连续赋值”也
  • 由于 OP 说“将文本与特定字符对齐,我还要添加检查 Array Initializers > Align key-value pairs
【解决方案4】:

在 PhpStorm 8 中,该选项位于:

File -> Settings -> Code style -> PHP -> Wrapping and Braces -> Assignment statement

【讨论】:

    【解决方案5】:

    Mac 上 2019.1 和更新版本的视觉更新:

    转到PHP Storm > Preferences > Editor > Code Style > PHP > Wrapping and Braces > Assignment Statement > Align consecutive assignments

    要激活它,请转到Code > Reformat Code 或按Cmd+Opt+L

    【讨论】:

      【解决方案6】:

      我们必须检查以下多个选项才能获得

      • 上面提到的问题
      • 数组的键值对对齐

      【讨论】:

        【解决方案7】:

        就我而言,我使用的是 PHPStorm 2021.2.3,

        Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> match expression -> Align 'match' arm bodies

        【讨论】:

          猜你喜欢
          • 2017-02-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-01-30
          • 1970-01-01
          • 2018-05-12
          • 1970-01-01
          相关资源
          最近更新 更多