Java Eclipse:设置自动格式化的最大行长?

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

Eclipse: Set maximum line length for auto formatting?

javaeclipseformattingide

提问by Nick Heiner

I am working with Java. If I hit Ctrl+Shift+Fin Eclipse Helios, it will auto format my code. At a certain point, it wraps lines. I would like to increase the maximum line length. How can I do this?

我正在使用 Java。如果我在 Eclipse Helios 中点击Ctrl+ Shift+ F,它会自动格式化我的代码。在某个时刻,它会环绕线条。我想增加最大行长度。我怎样才能做到这一点?

采纳答案by John Percival Hackworth

In preferences Java -> Code Style -> Formatter, edit the profile. Under the Line Wrappingtab is the primary option for line width (Maximum line width:). In the Commentstab you have a separate option Maximum line width for comments:, which will also need to be changed to affect comment wrapping.

在首选项Java -> Code Style -> Formatter 中,编辑配置文件。在Line Wrapping选项卡下是线宽的主要选项(最大线宽:)。在Comments选项卡中,您有一个单独的选项Maximum line width for comments:,它也需要更改以影响注释换行。

You will need to make your own profile to make these changes in if you using one of the [Built-in]ones. Just click "New..." on the formatter preferences page.

如果您使用其中之一,您将需要制作自己的配置文件以进行这些更改[Built-in]。只需在格式化程序首选项页面上单击“新建...”。

回答by Chozabu

Click Project->preferences. Type format into the search - you should see java->code style->formatter. Click that, then edit - finally, the line wrapping tab - its there :)

单击项目->首选项。在搜索中输入 format - 您应该看到java->code style->formatter。单击它,然后编辑 - 最后,换行选项卡 - 它在那里:)

回答by boukah

Comments have their own line length setting at the bottom of the setting page java->code style->formatter-> Edit... ->comments

注释在设置页面底部有自己的行长设置java->code style->formatter-> Edit... ->comments

回答by Amir Arad

for XML line width, update preferences > XML > XML Files > Editor > Line width

对于 XML 线宽,更新首选项 > XML > XML 文件 > 编辑器 > 线宽

回答by Sumit Singh

Take a look of following image:

看看下面的图片:

Java->Code style->Formatter-> Edit

enter image description here

在此处输入图片说明

回答by fbtb

For HTML / PHP / JSP / JSPF: Web -> HTML Files -> Editor -> Line width

对于 HTML/PHP/JSP/JSPF: Web -> HTML Files -> Editor -> Line width

回答by PhantomReference

For XHTML files: Web -> HTML Files -> Editor -> Line width

对于 XHTML 文件: Web -> HTML Files -> Editor -> Line width

回答by Roo

Preferences -> Java -> Code Style -> Formatter / "Edit..."

首选项 -> Java -> 代码样式 -> 格式化程序/“编辑...”

Tabs: "Line wrapping" , "Comments"

标签:“换行”、“注释”

Field: "Maximum line width"

字段:“最大线宽”

Set both to make comments have the same length too. You might need to create a new profile if you don't have one already.

设置两者以使评论也具有相同的长度。如果您还没有配置文件,则可能需要创建一个新配置文件。

回答by mannedear

I use the Eclipse version called Mars which works with Java 7.

我使用名为 Mars 的 Eclipse 版本,它适用于 Java 7。

Go to Preferences -> Java -> Code Style -> Formatter

转到首选项 -> Java -> 代码样式 -> 格式化程序

Click on the Edit Button shown in the right side of "Active Profile" drop down

单击“活动配置文件”下拉列表右侧显示的“编辑”按钮

Tabs: "Line wrapping"

标签:“换行”

Field: "Maximum line width", Set the desired value (Default value set to 120) to increase/decrease the line length in the editor

字段:“最大线宽”,设置所需值(默认值设置为 120)以增加/减少编辑器中的线长

Note: Remember to rename the Active profile to the name of your choice, as the default Eclipse profile won't accept your changes.

注意:记住将 Active 配置文件重命名为您选择的名称,因为默认的 Eclipse 配置文件不会接受您的更改。

回答by hariprasad

Line length formatter setup is blocked for annotations (Eclipse Photon checked). Therefore it is needed in Line Wrapping -> Wrapping settings -> Annotations. Setup line wrapping as appropriate for you. There is couple of possibilities, e.q. Enable wrap when necessaryto use first icon list.

注释行长度格式化程序设置被阻止(已选中 Eclipse Photon)。因此在Line Wrapping -> Wrapping settings -> Annotations 中需要它。根据您的需要设置换行。有几种可能性, eq必要时启用换行以使用第一个图标列表。