how to align text to specific character in phpstorm or webstorm?
Solution 1
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
For me in PhpStorm 8.0.2 I found it here:
Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> Align consecutive assignments
Solution 3
formatting option in phpstorm 8
settings > Code Style > php > Wrapping and braces
check both option Align fields in option and Align Constant
now you can get what you want! :)
Source Jetbrains Blog
Solution 4
In PhpStorm 8 that option is in:
File -> Settings -> Code style -> PHP -> Wrapping and Braces -> Assignment statement
Solution 5
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
.
Comments
-
Patrioticcow almost 2 years
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 ?
-
Jay Hardia almost 11 yearsIts not working for phpstorm 6.0.3 version although i did setting for this also. Can you help me
-
uross over 10 yearsI am using PhpStorm 6.0.3 on Win7 and I have "code reformat" on ALT+F8. That could probably depend on what OS you are using and your keymap setting. Click Code -> Reformat code in the menu - you should also see your keyboard shortcut by Reformat code menu option.
-
Dizzley over 10 yearsNote that there is also a setting to align key => value pairs (at least in PHPStorm 6.0.3). Great answer thanks.
-
SirDerpington over 10 yearsIs this also possible for JavaScript? I couldn't find the option there...:/
-
Dung almost 9 yearsIn phpStorm 9.x "Align fields in columns".
-
ASergey almost 8 years"Assignment statement > Align consecutive assignments" also
-
Nicolas C. over 7 yearsThe answer provided may be correct but the one @Sam provided is also essential.
-
Xhezairi over 6 yearsSince OP said "align text to specific character, I would also add check Array Initializers > Align key-value pairs.
-
sh6210 over 2 yearsI'm using PHPStorm 2021.2.3,
Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> match expression -> Align 'match' arm bodies