Eclipse PDT: How can I format it with my PHP arrays like VIM?

I am trying to get Eclipse to format my php arrays like vim indentation.

What the 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 tried looking in Settings> PHP> Code Style> Formatter and Preferences> PHP> Editor> Templates, but didn't find anything.
Thanks in advance. Cahan

+4
source share
6 answers

With Eclipse PDT Luna 4.4: select the Window \ Preferences menu. Select PHP \ Code Style \ Formatter .
Create a new Active profile , then click the Edit button.

enter image description here

In the Indentation tab Indentation select Default indentation for array initializers You must select a value of 1 (however, the default value is 2 ).

enter image description here


(after pressing Ctrl + Shift + F ) and the result will look like this:

enter image description here

+1
source

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

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

+8
source

Hmm, it looks like it's a PDT problem, see stack issue .

It is suggested to press a tab on the first carriage return, and the rest should follow the indent. As for CTRL + SHIFT + F, this will overwrite any manual formatting you have.

I don't know if you used Aptana Studio (using the PHP plugin), but this IDE is eclipse-based and may have the formatting options you want, Good luck :)

+3
source

I have been using the PDT formatter for several months now and it still does a great job.

I had to reinstall Indigo after I was unable to create a build for the 4.3 M5a developers with a full set of features. Here is how I did it:

+1
source

Formater's only complete configuration is the Java code style.

Windows / Preference / Java / Code Style / Formater edit profile, indent check indent instructions whitin

I don't know if this affects Formater PHP.

0
source

Mark this comment fooobar.com/questions/928778 / ...

The only thing missing:

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

0
source

All Articles