开发者

Eclipse PDT: How do I get it to format my PHP arrays like VIM?

开发者 https://www.devze.com 2022-12-10 13:28 出处:网络
I\'ve been struggling to get Eclipse to format my php arrays like vim indentation does. What eclipse do开发者_JS百科es (press CTRL+SHIFT+F)

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

What eclipse do开发者_JS百科es (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


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


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 :)


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

Eclipse PDT: How do I get it to format my PHP arrays like VIM?



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

Eclipse PDT: How do I get it to format my PHP arrays like VIM?


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

Eclipse PDT: How do I get it to format my PHP arrays like VIM?


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:

  • Installed Indigo (Classic)
  • Added http://download.eclipse.org/tools/pdt/updates/release to Available Software Sites and installed PDT
  • Saved the zip file (Dave Meybohm's answer) http://sourceforge.jp/downloads/users/1/1455/pdt_tools.formatter_1.5.0.v20120929.zip/ and added to the Available Software Sites as an archive and installed the formatter. Under Preferences -> PHP -> Code Style ->Formatter (PDT Tools) was available for customization.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消