如何自定义 Eclipse 的文本编辑器代码格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1790193/
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
How to customize Eclipse's text editor code formatting
提问by Eugeniu Torica
How can I set my Eclipse's code formatter to allow code rows longer than 80 characters. I know that very long lines is hard to read but in my opinion 80 characters per line is very small value for wide screen monitors.
如何设置 Eclipse 的代码格式化程序以允许超过 80 个字符的代码行。我知道很长的行很难阅读,但在我看来,每行 80 个字符对于宽屏显示器来说是非常小的值。
回答by BalusC
In Preferences, go to Java> Code Style> Formatterand edit/create the formatter and go to tab Line Wrapping. There in you can set the Maximum line width.
在 中Preferences,转到Java> Code Style>Formatter并编辑/创建格式化程序并转到 tab Line Wrapping。您可以在其中设置最大线宽。
Further on you can in General> Editors> Text Editorsalso set the Print margin columnwhich should shift up that margin (a 1px wide vertical line in the right side of your code) to the desired position. This however doesn't affect the formatter, only the human eye.
进一步上可以在General> Editors>Text Editors还设置了打印余量柱应该余量(在代码中的右侧1px的宽的垂直线)移动到所期望的位置。然而,这不会影响格式化程序,只会影响人眼。
回答by WhiskThimble
This answer was a bit old, and the path have changed with new versions of Eclipse.
这个答案有点旧,路径随着 Eclipse 的新版本而改变。
To set the Maximum line width, go to Project> Properties. In the Propertieswindow, go to Java Code Style> Formatter. Select your Active Profile(let the one which is already selected, this is the one you are currently using) and click on Edit. In the tab Line Wrapping, you can set the Maximum line width(80 by default). You can also go to the tab Commentsand uncheck Enable Line Comment Formattingif you want your comments not to be formatted on multiple lines with Ctrl+Shift+F.
要设置最大线宽,请转到Project> Properties。在Properties窗口中,转到Java Code Style> Formatter。选择您的Active Profile(让已经选择的那个,这是您当前使用的那个)并单击Edit。在选项卡中Line Wrapping,您可以设置最大线宽(默认为 80)。您也可以转到标签Comments和取消Enable Line Comment Formatting,如果您希望您的意见并不多条线路上进行格式化Ctrl+ Shift+ F。
Don't forget to change the nameof the Profile Name; if you don't change it, you won't be able to save your changes (provided the one you are editing is Built-In
不要忘了改名字的Profile Name; 如果您不更改它,您将无法保存更改(前提是您正在编辑的是内置的)
Also, you can set the Print margin columnin Window> Preferences> General> Editors> Text Editors.
此外,您可以在> > > > 中设置打印边距列。WindowPreferencesGeneralEditorsText Editors
回答by VonC
Regarding the "small" value (80), this has just changed (in August 2014).
See "Eclipse is not a terminal anymore – Default line size of Java code formatter is now 120"
(By Lars Vogel)
关于“小”值 (80),这刚刚改变(2014 年 8 月)。
请参阅“ Eclipse 不再是终端——Java 代码格式化程序的默认行大小现在为 120”
(作者:Lars Vogel)
Project> Properties, Java Code Style> Formatter.
Project> Properties, Java Code Style> Formatter。
Edittab Line Wrapping
Edit标签 Line Wrapping
A three-years old issue is finally addressed:
bug 356851: Default line size of Java code formatter should be increased to 120
一个三年前的问题终于得到解决:
错误 356851:Java 代码格式化程序的默认行大小应该增加到 120
It is not mentioned in the Eclipse Project 4.5 (Mars) M1 - New and Noteworthy, but it is still "Verified for 4.5 M1 using I20140804-2000 build".
在Eclipse Project 4.5 (Mars) M1 - New andNoteworthy 中没有提到它,但它仍然是“使用 I20140804-2000 版本验证 4.5 M1”。