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

22,487

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

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

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.

enter image description here

Share:
22,487
Patrioticcow
Author by

Patrioticcow

spooky action at a distance

Updated on July 09, 2022

Comments

  • Patrioticcow
    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
    Jay Hardia almost 11 years
    Its not working for phpstorm 6.0.3 version although i did setting for this also. Can you help me
  • uross
    uross over 10 years
    I 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
    Dizzley over 10 years
    Note that there is also a setting to align key => value pairs (at least in PHPStorm 6.0.3). Great answer thanks.
  • SirDerpington
    SirDerpington over 10 years
    Is this also possible for JavaScript? I couldn't find the option there...:/
  • Dung
    Dung almost 9 years
    In phpStorm 9.x "Align fields in columns".
  • ASergey
    ASergey almost 8 years
    "Assignment statement > Align consecutive assignments" also
  • Nicolas C.
    Nicolas C. over 7 years
    The answer provided may be correct but the one @Sam provided is also essential.
  • Xhezairi
    Xhezairi over 6 years
    Since OP said "align text to specific character, I would also add check Array Initializers > Align key-value pairs.
  • sh6210
    sh6210 over 2 years
    I'm using PHPStorm 2021.2.3, Settings -> Editor -> Code Style -> PHP -> Wrapping and Braces -> match expression -> Align 'match' arm bodies