Search code examples
intellij-ideaphpstorm

Spaces / align of variable definitions in IntelliJ


I have this:

    $accountNr = $csvData[2][1];
$firstname = $csvData[3][1];
$lastname = $csvData[4][1];
$telephone1 = $csvData[5][1];
$telephone2 = $csvData[6][1];
$telephone3 = $csvData[7][1];
$telephone4 = $csvData[8][1];
$email1 = $csvData[9][1];
$email2 = $csvData[10][1];
$email3 = $csvData[11][1];
$email4 = $csvData[12][1];
$address1 = $csvData[13][1];
$address2 = $csvData[14][1];
$zip = $csvData[15][1];
$state = $csvData[16][1];

I want this:

$accountNr  = $csvData[2][1];
$firstname  = $csvData[3][1];
$lastname   = $csvData[4][1];
$telephone1 = $csvData[5][1];
$telephone2 = $csvData[6][1];
$telephone3 = $csvData[7][1];
$telephone4 = $csvData[8][1];
$email1     = $csvData[9][1];
$email2     = $csvData[10][1];
$email3     = $csvData[11][1];
$email4     = $csvData[12][1];
$address1   = $csvData[13][1];
$address2   = $csvData[14][1];
$zip        = $csvData[15][1];
$state      = $csvData[16][1];

There is a IntelliJ plugin called "String Manipulation" that does exactly that.

But: when I select the whole file and format it using the formatting of PhpStorm, everything gets changed again.

Is there a different cleaner way to do it?


Solution

    1. Settings/Preferences
    2. Editor | Code Style | PHP
    3. Wrapping and Braces --> Assignment statement
    4. Activate Align consecutive assignments option

    enter image description here