如何在 Eclipse 中保存时禁用自动格式化?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5199255/
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-10 20:00:26  来源:igfitidea点击:

How to disable auto formatting upon save in Eclipse?

eclipseformatting

提问by Oliver

Eclipse keeps auto formatting upon save, for example: it is insisting the following code should be in a single line once I save, despite breaking it up the way I want to.

Eclipse 在保存时保持自动格式化,例如:它坚持以下代码在我保存后应该在一行中,尽管按照我想要的方式分解它。

@Transactional(rollbackFor = DataAccessException.class, readOnly = false, timeout = 30, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT)

回答by dty

Window > Preferences > Java > Editor > Save Actions.

窗口 > 首选项 > Java > 编辑器 > 保存操作。

Can also be configured at the project level. Project > Properties > Java Editor > Save Actions.

也可以在项目级别进行配置。项目 > 属性 > Java 编辑器 > 保存操作。

回答by Mike

Absolutely maddening improvement. For if statements do the following: Window | Preferences | Java | Code Style | Formatter | Control statements tab Select Keep simple if on one line. You might also try the Line wrappingtab

绝对令人抓狂的改进。对于 if 语句执行以下操作: Window | 偏好 | 爪哇| 代码风格 | 格式化程序 | 控制语句选项卡选择保持简单,如果在一行上。您也可以尝试换行选项卡

回答by VdeX

This is a Late answer, But just for novice to understand it clearly I have a snapshot of the setting. Please follow the path on left.
And change highlighted setting. enter image description here

这是一个迟到的答案,但只是为了让新手清楚地理解它,我有一个设置的快照。请沿着左边的路走。
并更改突出显示的设置。 在此处输入图片说明

回答by Thierry

If you wish to keep the auto-formatter, but don't want this behavior, you can also configure it in the fomatter :

如果您希望保留自动格式化程序,但不希望出现此行为,您还可以在 fomatter 中配置它:

right click on the project -> properties -> java code style -> formatter

(If you don't have a project specific formatter the global configuration can be accessed this way : Window -> Preference -> Java -> Code Style -> Formatter).

(如果您没有特定于项目的格式化程序,则可以通过这种方式访问​​全局配置:)Window -> Preference -> Java -> Code Style -> Formatter

Edit...the active profile, open the Line Wrapping tab, and there check the Never join already wrapped linesoption.

Edit...活动配置文件,打开 Line Wrapping 选项卡,然后选中该Never join already wrapped lines选项。

This way you can wrap lines wherever you want and eclipse won't remove your line breaks (which is a must if you wish to have readable lambda expressions), but keep the formatter active.

这样你就可以在任何你想要的地方换行,eclipse 不会删除你的换行符(如果你希望有可读的 lambda 表达式,这是必须的),但保持格式化程序处于活动状态。

This option is there at least since eclipse Luna

这个选项至少在 eclipse Luna 之后就存在了

Here is a screenshot where this option is : enter image description here

这是此选项所在的屏幕截图: 在此处输入图片说明

回答by Strucker

Just wanted to add a tip. If you want to avoid the line wrapping you can simply increase the "Maximum line width" value to something enormous. As long as that is sufficiently high eclipse won't do any wrapping.

只是想补充一点。如果你想避免换行,你可以简单地将“最大线宽”值增加到很大的值。只要那足够高 eclipse 就不会做任何包装。

Preferences > Java > Code Style > Formatter > Edit > Line Wrapping > Maximum line width

首选项 > Java > 代码样式 > 格式化程序 > 编辑 > 换行 > 最大线宽