577

I am working with Java. If I hit Ctrl+Shift+F in 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?

1
  • 3
    Note: starting Eclipse Mars 4.5 M1 (August 2014), the default line length in Eclipse is 120 (instead of 80). See my answer. Commented Aug 11, 2014 at 18:34

10 Answers 10

732

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

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.

Sign up to request clarification or add additional context in comments.

9 Comments

This wasn't working for me so I disabled formatting of comment lines entirely. It's nearly exactly the same except instead of the 'Line Wrapping' tab you want 'Comments' tab and uncheck 'Enable line comment formatting'
This is the correct answer, althought it doesn't force the width on comments. Go to the "Comments" tab, and on the bottom there's the field "Line width" to change the maximum line width for comments.
Note: Eclipse (Kepler, at least) very obnoxiously allows you to edit the built-in profile to your heart's content, only to stop you from saving it with an unobtrusive notification that you CAN'T edit built-in profiles, and must create a copy and edit that instead.
"Line Wrapping tab" is not a complete answer. As Henrique Sousa and some other IDs mentioned, it still need to go to "Comments" tab. I was bugged by line-wrapping in comments. :)
Using Luna at least, all you have to do is change the text field at the top of the options tabs to something other than Eclipse [Default] and click Apply. It saved all my modifications I was trying to make to the default profile.
|
122

Take a look of following image:

Java->Code style->Formatter-> Edit 

enter image description here

4 Comments

You forgot steps showing how to get to the preferences window =) Window > Preferences
@rodrigo-silveira That's platform dependent, actually. On a Mac it's Eclipse -> Preferences.
If you use Mac, the "Preference" menu is located in "Eclipse" menu, but not in "Window" menu.
You forgot the part where you have to create a new "Active profile". Otherwise you will not be able to change any settings.
38

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

Comments

30

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

Comments

21

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

Comments

9

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 :)

Comments

7

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

Comments

6

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

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.

Comments

2

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

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

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

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

Comments

1

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 necessary to use first icon list.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.