简体   繁体   中英

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

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 ?

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.

For me in PhpStorm 8.0.2 I found it here:

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

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

在PhpStorm 8中,该选项包括:

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

A visual update for 2019.1 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 .

在此输入图像描述

We have to check multiple options as below to get

  • Problem mentioned above
  • Key value pair alignment of array

在此输入图像描述

In my case i'm using PHPStorm 2021.2.3,

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM