561

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?

hariprasad
  • 455
  • 10
  • 20
Nick Heiner
  • 108,809
  • 177
  • 454
  • 689
  • 3
    Note: starting Eclipse Mars 4.5 M1 (August 2014), the default line length in Eclipse is 120 (instead of 80). See [my answer](http://stackoverflow.com/a/25250064/6309). – VonC Aug 11 '14 at 18:34

10 Answers10

713

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.

BeeOnRope
  • 51,419
  • 13
  • 149
  • 309
John Percival Hackworth
  • 11,119
  • 2
  • 29
  • 38
  • 9
    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' – anon58192932 Jul 02 '13 at 18:24
  • Something may have changed. What version of eclipse are you using? – John Percival Hackworth Jul 04 '13 at 04:40
  • 49
    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. – Henrique de Sousa Oct 02 '13 at 12:59
  • 6
    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. – kungphu Dec 13 '13 at 16:59
  • 3
    "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. :) – user1914692 Mar 03 '14 at 19:51
  • 1
    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. – JReader Jun 16 '15 at 16:26
  • That would be a great improvement. – John Percival Hackworth Jun 16 '15 at 19:54
  • is there a way to have eclipse throw a warning when a line is longer then the margin? – Martin Klosi Jan 27 '16 at 22:21
  • If "Maximum line width for comments" is greyed out, you first need to enable some types of comments which you want to format (first four checkboxes). – Line Dec 28 '17 at 10:10
122

Take a look of following image:

Java->Code style->Formatter-> Edit

enter image description here

Sumit Singh
  • 23,530
  • 8
  • 71
  • 99
38

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

Sumit Singh
  • 23,530
  • 8
  • 71
  • 99
boukah
  • 391
  • 3
  • 2
29

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

Sumit Singh
  • 23,530
  • 8
  • 71
  • 99
Amir Arad
  • 6,436
  • 8
  • 40
  • 47
20

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

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
fbtb
  • 789
  • 10
  • 22
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 :)

Sumit Singh
  • 23,530
  • 8
  • 71
  • 99
Chozabu
  • 975
  • 1
  • 8
  • 33
6

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

PhantomReference
  • 618
  • 1
  • 12
  • 25
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.

Roo
  • 101
  • 1
  • 2
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.

mannedear
  • 1,027
  • 14
  • 24
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.

hariprasad
  • 455
  • 10
  • 20