4

I've been struggling to get Eclipse to format my php arrays like vim indentation does.

What eclipse does (press CTRL+SHIFT+F)

<?php
$array = array(
'key1' => 'value1',
'key2' => array(
'child_key1' => 'child_value1',
'child_key2' => 'child_value2',
),
);

What vim does (press keys:gg=G)

<?php
$array = array(
  'key1' => 'value1',
  'key2' => array(
    'child_key1' => 'child_value1',
    'child_key2' => 'child_value2',
    ),  
  );  

I've tried looking in Preferences>PHP>Code Style>Formatter and Preferences>PHP>Editor>Templates but haven't found anything.
Thanks in advance.
Kehan

5 Answers 5

8

Check out this project. Put the jar file in your eclipse/dropins folder, and then you can go to preferences/php/code style/formatter. It has a cool "Align => column position in array" option under the "Miscellaneous" section (click the arrow on the options tab to expand) that does something similar to what you want. Use Ctrl-Shift-F to format an entire file, or right-click a selection and checkout the "Source->Format..." options.

http://de.sourceforge.jp/projects/pdt-tools/releases/?package_id=8764

Sign up to request clarification or add additional context in comments.

3 Comments

You can vote to try and get this feature added to PDT @ bugs.eclipse.org/bugs/show_bug.cgi?id=320130
The project being dead, where can I find this jar right now ?
I still had the original jar, I added it to my github. I made some small modifications to comply with coding standards at my job. You can also download the original version from in the bin directory: github.com/dmeybohm/Eclipse-PHP-Formatter
3

Hmm looks like this is still a problem with PDT, See stack related question.

It suggests pushing tab on the first carriage return and the rest should follow the indentation after that. As for CTRL+SHIFT+F this will overwrite any manual formatting you have in place.

I don't know if you have used Aptana Studio (with the PHP plug-in) before but this IDE is eclipse based and might have the formatting options you want, Good luck :)

1 Comment

Thanks for that - problem is I use CTRL+SHIFT+F all the time. I'm trying aptana (again) will post feedback here. Cheers, K
1

With Eclipse PDT Luna 4.4: Choose menu Window \ Preferences. Choose PHP \ Code Style \ Formatter.
Create new Active profile then press button Edit.

enter image description here

In tab Indentation, choose Default indentation for array initializers You should choose value 1 (however, default value is 2).

enter image description here


(after press Ctrl+Shift+F ) and result will like this:

enter image description here

Comments

1

I have been using PDT formatter for several months and it does a great job so far.

I had to reinstall Indigo after I failed to get developer build 4.3 M5a running full-featured. Here is how I did:

Comments

1

Check out this comment https://stackoverflow.com/a/19702960/2709131

The one thing that was missing was:

Line Wrapping > Expressions > Array initializers > Indentation policy > Indent by one

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.