我记得在IntelliJ或Eclipse中看到每当保存文件时重新格式化(清理)文件的设置。我怎么找到它(在设置中没有找到它)
当前回答
从2020.1版本开始,你可以直接在pretty插件的Preferences中激活Run on save for file:
其他回答
Ctrl + Alt + L是格式文件(包括下面两个)
Ctrl + Alt + O是优化导入
Ctrl + Alt +我将在特定的行上修复缩进
在提交工作之前,我通常会运行几次Ctrl + Alt + L。我宁愿它做清理/重新格式化在我的命令,而不是自动。
如果你有InteliJ Idea Community 2018.2及以上版本,步骤如下:
In the top menu you click: Edit > Macros > Start Macro Recordings (you'll see a window lower right corner of your screen confirming that macros are being recorded) In the top menu you click: Code > Reformat Code (you'll see the option being selected in the lower right corner) In the top menu you click: Code > Optimize Imports (you'll see the option being selected in the lower right corner) In the top menu you click: File > Save All In the top menu you click: Edit > Macros > Stop Macro Recording You name the macro: "Format Code, Organize Imports, Save" In the top menu you clock: File > Settings. In the settings windows you click Keymap In the search box on the right you search "save". You'll find Save All (Ctrl+S). Right click on it and select "Remove Ctrl+S" Remove your search text from the box, press on the Collapse All button (Second button from the top left) Go to macros, press on the arrow to expand your macros, find your saved macro and right click on it. Select Add Keyboard Shortcut, and press Ctrl+S and okay.
重新启动IDE并尝试它。
我知道你要说什么,在我之前的人也写过同样的东西。但我在使用本文上面的步骤时感到困惑,我想为拥有最新版本IDE的人编写一个简化版本。
我建议使用save actions插件。它还支持优化导入和重新排列代码。
可以很好地与eclipse格式化器插件结合使用。
搜索并激活插件:
配置:
编辑:似乎它最近版本的Intellij保存动作插件是由自动Intellij保存触发的。这可能是相当恼人的,当它仍然在编辑。
这个插件的github问题给出了一些可能的解决方案:
https://github.com/dubreuia/intellij-plugin-save-actions/issues/63
我实际上试图将重新格式化分配给Ctrl+S,它工作得很好-保存现在是自动完成的。
我重新绑定了重新格式化代码…操作到Ctrl-S,取代默认绑定保存全部。
乍听起来可能有些疯狂,但IntelliJ似乎节省了几乎每一个操作:运行测试、构建项目,甚至关闭编辑器选项卡。我有一个经常按Ctrl-S的习惯,所以这实际上对我来说很好。在重新格式化时,输入它当然比默认绑定更容易。
IntellIJ 14 && 15:当你在提交更改对话框签入代码时,勾选“重新格式化代码”复选框,然后IntellIJ将重新格式化你签入的所有代码。
来源:www.udemy.com/intellij-idea-secrets-double-your-coding-speed-in-2-hours
推荐文章
- 如何查看IntelliJ中的编译错误列表?
- 类未找到:IntelliJ中的空测试套件
- 设置TextView文本从html格式的字符串资源在XML
- Intellij IDEA Java类在保存时不能自动编译
- Android Studio中的。iml文件是什么?
- 为什么IntelliJ 13 IDEA从12版本升级后这么慢?
- intellij是否可以像在Eclipse中那样组织导入?
- 格式化XML字符串以打印友好的XML字符串
- 导入时无法解析符号
- 如何从IntelliJ IDEA搜索中排除文件扩展名?
- IntelliJ IDEA输出窗口切割输出
- 如何让IntelliJ识别常见的Python模块?
- 如何在Intellij生成串行版本UID
- 如何同步项目到GitHub与Android工作室?
- IntelliJ IDEA with Junit 4.7”!!JUnit 3.8或更高版本: