我记得在IntelliJ或Eclipse中看到每当保存文件时重新格式化(清理)文件的设置。我怎么找到它(在设置中没有找到它)


当前回答

IntellIJ 14 && 15:当你在提交更改对话框签入代码时,勾选“重新格式化代码”复选框,然后IntellIJ将重新格式化你签入的所有代码。

来源:www.udemy.com/intellij-idea-secrets-double-your-coding-speed-in-2-hours

其他回答

我以为IntelliJ中有类似的东西,但我找不到。保存时发生的唯一清理是删除行尾的空白。我认为我必须在某一时刻指定这种行为,但在这一点上我没有看到任何相关的东西。

IntellIJ 14 && 15:当你在提交更改对话框签入代码时,勾选“重新格式化代码”复选框,然后IntellIJ将重新格式化你签入的所有代码。

来源:www.udemy.com/intellij-idea-secrets-double-your-coding-speed-in-2-hours

我建议使用save actions插件。它还支持优化导入和重新排列代码。

可以很好地与eclipse格式化器插件结合使用。

搜索并激活插件:

配置:

编辑:似乎它最近版本的Intellij保存动作插件是由自动Intellij保存触发的。这可能是相当恼人的,当它仍然在编辑。

这个插件的github问题给出了一些可能的解决方案:

https://github.com/dubreuia/intellij-plugin-save-actions/issues/63

我实际上试图将重新格式化分配给Ctrl+S,它工作得很好-保存现在是自动完成的。

这个解决方案对我来说效果更好:

制作一个宏(我使用了组织导入,格式化代码,保存全部) 给它分配一个击键(我重写了Ctrl+S)

注意:对于有组织的导入,您必须在第一次选中“不再显示此消息”复选框,但在此之后它将按预期工作。

IntelliJ 10.0的步骤:

Code -> "Optimize Imports...", if a dialogue box appears, check the box that says "Do not show this message again.", then click "Run". Tools -> "Start Macro Recording" Code -> "Optimize Imports..." Code -> "Reformat Code..." File -> "Save all" Tools -> "Stop Macro Recording" Name the macro (something like "formatted save") In File -> Settings -> Keymap, select your macro located at "Main Menu -> Tools -> "formatted save" Click "Add Keyboard Shortcut", then perform the keystroke you want. If you choose Ctrl+S like me, it will ask you what to do with the previous Ctrl+S shortcut. Remove it. You can always reassign it later if you want. Enjoy!

对于IntelliJ 11,请替换

步骤2。使用:编辑->宏->“开始宏录制” 步骤6。使用:编辑->宏->“停止宏录制”

其他一切都保持不变。

IntelliJ 12

8. 首选项包含Keymap设置。使用输入字段过滤内容,如截图所示。

Ctrl + Alt + L是格式文件(包括下面两个)

Ctrl + Alt + O是优化导入

Ctrl + Alt +我将在特定的行上修复缩进

在提交工作之前,我通常会运行几次Ctrl + Alt + L。我宁愿它做清理/重新格式化在我的命令,而不是自动。