how to align text to specific character in phpstorm or webstorm?

PhpTextAlignmentPhpstormWebstorm

Php Problem Overview


I have this text

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

and I would like to align it like this, using tabs,

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

is there a way of doing this in phpstorm or webstorm ?

Php Solutions


Solution 1 - Php

Cmd+Alt+L (in Mac) or Ctrl+Alt+L (Win) and PHP Storm will format code depends of your Code style in Settings. TO set this code style go: File -> Settings -> Code style -> PHP(choose here your language) -> Other -> Align key-value pair - mark as checked. And then press Reformat code (Ctrl+Alt+L) and voila. You will get code, styled you write above.

Solution 2 - Php

For me in PhpStorm 8.0.2 I found it here:

> Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> Align consecutive assignments

Solution 3 - Php

formatting option in phpstorm 8

settings > Code Style > php > Wrapping and braces

enter image description here

check both option Align fields in option and Align Constant

now you can get what you want! :)

Source Jetbrains Blog

Solution 4 - Php

In PhpStorm 8 that option is in:

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

Solution 5 - Php

A visual update for 2019.1 and newer versions on Mac:

Go to PHP Storm > Preferences > Editor > Code Style > PHP > Wrapping and Braces > Assignment Statement > Align consecutive assignments.

To activate it go to Code > Reformat Code or press Cmd+Opt+L.

enter image description here

Solution 6 - Php

We have to check multiple options as below to get

  • Problem mentioned above
  • Key value pair alignment of array

enter image description here

Solution 7 - Php

In my case i'm using PHPStorm 2021.2.3, > Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> match expression -> Align 'match' arm bodies

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPatrioticcowView Question on Stackoverflow
Solution 1 - PhpLIALView Answer on Stackoverflow
Solution 2 - PhpSamView Answer on Stackoverflow
Solution 3 - PhpmaqView Answer on Stackoverflow
Solution 4 - PhpnwrmanView Answer on Stackoverflow
Solution 5 - PhpAndresView Answer on Stackoverflow
Solution 6 - PhpVeshraj JoshiView Answer on Stackoverflow
Solution 7 - Phpsh6210View Answer on Stackoverflow