Intellij IDEA,格式化项目中的所有代码
我真的很喜欢 IDEA 的代码格式化,但是如何让它在不遍历每个文件的情况下重新格式化特定项目中的所有代码?我找到了在将代码提交到 subversion 之前整理/优化代码导入的选项,这很棒,但它似乎只适用于已修改的文件(这在大多数情况下是明智的!)
有没有办法自动格式化项目中的所有源文件而不需要手动检查它们?
I really like IDEA's code formatting, but how do I get it to reformat all the code in a particular project without going through each file? I've found the option to tidy / optimise imports on code before committing it to subversion which is great, but it only seems to apply to files that have otherwise been modified (which is sensible in the majority of cases!)
Is there a way to auto-format all the source files in a project without going through them all by hand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在树形结构中,右键单击要重新格式化的文件夹,从菜单中选择“重新格式化代码”。
In the tree-structure, right click on the folder you like to reformat, choose "Reformat code" from the menu.
当您要求重新格式化时,选择“整个项目”单选按钮而不是单个文件。
请注意一个问题:如果您正在与其他不符合您风格的开发人员一起开发一个更大的项目,并且您每次编辑代码时都使用 IntelliJ 来转换他们的所有代码,那么您可能会导致你的版本控制系统有问题。当您签入时,将会发生大量更改,其中很少有与更改功能有关的更改。在这种情况下最好符合团体风格。
Choose the "whole project" radio button instead of the individual file when you ask to reformat.
Just be aware of one problem: If you're working on a larger project with other developers who don't conform to your style, and you're using IntelliJ to transform all their code every time you edit it, you might be causing a problem with your version control system. It will long a huge volume of changes when you check in, and few of them will have anything to do with changing functionality. Better to conform to the group style in that case.
根据 iDea:编辑器基础文档
:可以使用快捷键 Ctrl+ALT+L (Windows/Linux) 或 ⌥⌘+L (MAC OS X) 并选择重新排列条目选项以重新格式化当前文件中的代码或重新格式化模块或目录(选择多个文件后)。
您还可以从上下文菜单中右键单击模块、文件或目录,然后选择重新格式化代码,然后选择重新排列条目选项。
您还可以通过选择优化导入选项来优化文件的导入。
某些 Linux 版本中,快捷键 Ctrl+ALT+L 可以锁定屏幕,因此您需要右键单击某个文件或目录单击上下文菜单,选择重新格式化代码,然后选择重新排列条目选项。
这适用于大多数 Jetbrains IDES(iDea、PyCharm、WebStorm、RubyMine 等)。
According the iDea: Editor basics documentation:
You can use the shortcut Ctrl+ALT+L (Windows/Linux) or ⌥⌘+L (MAC OS X) and select the Rearrange entries option to reformat the code in the current file or reformat a module or directory (after selecting more than one file).
You can also Right-click a module, file, or directory from the context menu and select Reformat Code and also select the Rearrange entries option.
You can also optimize the imports of your files by selecting the Optimize imports option.
Is some Linux versions the shortcut Ctrl+ALT+L can lock the screen, so you will need to Right-click a file or directory from the context menu and select Reformat Code and also select the Rearrange entries option.
This works for most of the Jetbrains IDES (iDea, PyCharm, WebStorm, RubyMine, and so on.)
“CTRL + ALT + L”仅适用于 Windows。
“CTRL + ALT + L”是 Ubuntu 锁定屏幕快捷键,因此它对此不起作用。
尝试,
右键单击您要重新格式化的文件夹,从菜单中选择“重新格式化代码”或单击顶部导航栏上的“代码”按钮,选择“重新格式化代码”
谢谢
"CTRL + ALT + L" work only windows.
"CTRL + ALT + L" is Ubuntu Lock screen shortcut key so its not working for this.
Try ,
Right click on the folder you like to reformat, choose "Reformat code" from the menu or click "Code" button on navigation bar in top, choose "Reformat code"
Thank you