本文翻译自:How to auto-format code in Eclipse?
你如何在Eclipse中自动格式化代码?
#1楼
参考:https://stackoom.com/question/13gc2/如何在Eclipse中自动格式化代码
#2楼
On Windows : Ctrl + Shift + F 在Windows上 : Ctrl + Shift + F.
On Mac : ⌘ + ⇧ + F 在Mac上 : ⌘ + ⇧ + F.
(Alternatively you can press Format
in Main Menu > Source) (或者您可以按主菜单>来源中的Format
)
#3楼
Another option is to go to Window->Preferences->Java->Editor->SaveActions and check the Format source code option. 另一种选择是转到Window-> Preferences-> Java-> Editor-> SaveActions并检查Format source code选项。 Then your source code will be formatted truly automatically each time you save it. 然后,每次保存时,您的源代码都将自动格式化。
#4楼
按: Ctrl + A或突出显示要缩进的代码部分,然后按ctrl + i 。
#5楼
CTRL + SHIFT + F将自动格式化您的代码(无论是突出显示还是非突出显示)。
#6楼
Windows -> Preferences -> Java -> Editor -> save actions -> Format source code -> Format Edited lines (or) format all lines. Windows - >首选项 - > Java - >编辑器 - >保存操作 - >格式化源代码 - >格式编辑行(或)格式化所有行。
Some time when you work as a team, lead don't want you to format all lines of the code in a source file (Huge track changes will be there on commit). 有些时候,当你作为一个团队工作时,领导者不希望你在源文件中格式化代码的所有行(巨大的轨道更改将在提交时出现)。 So, select 'Format Edited lines'. 因此,选择“格式编辑的行”。 This will edit and format only the lines you modified. 这将仅编辑和格式化您修改的行。
Gubs 广东商学院