Eclipse PDT:如何让它像 VIM 一样格式化我的 PHP 数组?
我一直在努力让 Eclipse 像 vim 缩进一样格式化我的 php 数组。
eclipse 做什么(按 CTRL+SHIFT+F)
<?php
$array = array(
'key1' => 'value1',
'key2' => array(
'child_key1' => 'child_value1',
'child_key2' => 'child_value2',
),
);
vim 做什么(按键:gg=G)
<?php
$array = array(
'key1' => 'value1',
'key2' => array(
'child_key1' => 'child_value1',
'child_key2' => 'child_value2',
),
);
我尝试在“首选项”>“PHP”>“代码样式”>“格式化程序”和“首选项”>“PHP”>“编辑器”>“模板”中查找,但没有找到任何内容.
提前致谢。
克汉
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看看这个项目。将 jar 文件放入 eclipse/dropins 文件夹中,然后您可以转到preferences/php/code style/formatter。它在“杂项”部分下有一个很酷的“对齐 => 数组中的列位置”选项(单击选项选项卡上的箭头展开),它可以执行与您想要的类似的操作。使用 Ctrl-Shift-F 格式化整个文件,或右键单击所选内容并检查“源 -> 格式...”选项。
http://de.sourceforge.jp/projects/pdt-tools/发布/?package_id=8764
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
嗯,看起来这仍然是 PDT 的问题,请参阅堆栈相关问题< /a>.
它建议按第一个回车符上的选项卡,其余部分应遵循此后的缩进。至于 CTRL+SHIFT+F,这将覆盖您已有的任何手动格式。
我不知道你以前是否使用过Aptana Studio(带有PHP插件)但是这个IDE是基于 Eclipse 的,可能有你想要的格式选项,祝你好运:)
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 :)
对于 Eclipse PDT Luna 4.4:选择菜单
Window \ Preferences
。选择PHP \ Code Style \ Formatter
。创建新的
活动配置文件
,然后按编辑
按钮。在
缩进
选项卡中,选择默认数组初始值设定项的缩进
您应该选择值1
(但是,默认值为2
)。(按 Ctrl+Shift+F ),结果将如下所示:
With Eclipse PDT Luna 4.4: Choose menu
Window \ Preferences
. ChoosePHP \ Code Style \ Formatter
.Create new
Active profile
then press buttonEdit
.In tab
Indentation
, chooseDefault indentation for array initializers
You should choose value1
(however, default value is2
).(after press Ctrl+Shift+F ) and result will like this:
我已经使用 PDT 格式化程序几个月了,到目前为止它的表现非常好。
在无法让开发人员构建 4.3 M5a 运行全功能后,我不得不重新安装 Indigo。这是我的做法:
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:
查看此评论 https://stackoverflow.com/a/19702960/2709131
缺少的一件事是:
<代码>换行>表达式>数组初始值设定项 >缩进政策>缩进一位
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