如何在 Eclipse 中重新缩进我的所有代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1207264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:55:47  来源:igfitidea点击:

How do I reindent all my codes in Eclipse?

eclipseideclojure

提问by unj2

In most of the IDEs, I had a Reindent All command. How do I do that in Eclipse 1.2?

在大多数 IDE 中,我有一个 Reindent All 命令。我如何在 Eclipse 1.2 中做到这一点?

Edit: The commands work with Java codes but is there a way I can get it to work with Clojure?

编辑:这些命令适用于 Java 代码,但有没有办法让它与 Clojure 一起使用?

回答by Yuval Adam

Ctrl+Shift+F

Ctrl+ Shift+F

will format all your code according to active formatting rules, this includes any indentation rules you defined (tabs/spaces, amount of those, etc...)

将根据活动的格式规则格式化您的所有代码,这包括您定义的任何缩进规则(制表符/空格,这些规则的数量等...)

You can change those rules at:

您可以在以下位置更改这些规则:

  • Window > Preferences
  • Java > Code Style > Formatter
  • 窗口 > 首选项
  • Java > 代码样式 > 格式化程序

回答by Antoine Claval

Is CRTL+SHIFT+Fworking in eclipse 1.2 ? In 3.5 is working fine.

CRTL + SHIFT + F在Eclipse 1.2的工作?在 3.5 中工作正常。

You can also select all the code you want to indent, and then hit CTRL + I

您也可以选择所有要缩进的代码,然后按CTRL + I

回答by matt b

Eclipse is up to version 3.5 now. You mightwant to upgrade.

Eclipse 现在是 3.5 版。您可能想要升级。

To format your code however you like, including indentation and a dozen other minute details that you might care about, you can set Formatter options (under Preferences / Java / Code Style / Formatter). You can also tell Eclipse to run the Formatter on every save, along with other rules.

要以您喜欢的方式格式化您的代码,包括缩进和您可能关心的其他十几个细节,您可以设置 Formatter 选项(在 Preferences / Java / Code Style / Formatter 下)。您还可以告诉 Eclipse 在每次保存时运行格式化程序以及其他规则。

回答by dls

TABand SHIFT+TABshould also work for selected lines of code/text - provided your tab character is configured to be equal to your indent space count.

TABSHIFT+TAB也应该适用于选定的代码/文本行 - 前提是您的制表符配置为等于您的缩进空间计数。