How to auto-format code in Eclipse?

2019-01-04 15:46发布

How do you auto-format code in Eclipse?

11条回答
【Aperson】
2楼-- · 2019-01-04 16:00

right-click on the project > Properties > Java Editor > Save Actions

查看更多
戒情不戒烟
3楼-- · 2019-01-04 16:04

Another option is to go to Window->Preferences->Java->Editor->SaveActions and check the Format source code option. Then your source code will be formatted truly automatically each time you save it.

查看更多
Explosion°爆炸
4楼-- · 2019-01-04 16:04

Notice: It did not format the document unless I corrected all mistakes. Check your file before pressing CTRLSHIFTF.

查看更多
你好瞎i
5楼-- · 2019-01-04 16:08

You can do with some step bellow

Step 1: press Ctr + A(windows) or cmd + A (Mac os)

Step 2: Ctr + I in windows or cmd + I in Mac os

It will auto format for you

Regards

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-04 16:11

Press: Ctrl + A or highlight the part of the code you wish to indent and then press ctrl + i.

查看更多
Explosion°爆炸
7楼-- · 2019-01-04 16:11

Update your IDE with the latest PDT version for better code formatting. On the main menu click Help -> Install New Software and then add the following URL in the Work with field:

http://download.eclipse.org/tools/pdt/updates/4.0.1 

When asked for the name, give it PDT4.0.1 and then move along with the update or install.

It will see if the appropriate PDT is already installed or if it is a lower version, which then would be updated.

After restarting or applying the changes go to Windows -> Preferences on the side bar and expand PHP -> Code Style. Here you will see an item named Formatter. Select it and choose the active profile for the code formating. Thats it.

The next time you format it, it will choose a format according to the chosen active profile.

Hope it helps.

查看更多
登录 后发表回答