29

Does anybody know how to turn line breaking in eclipse after you press CTRL + SHIFT + F (code format), ex :

System.err
                    .println("Incorrect file name, make sure you include .extension with your file name");
ant
  • 22,634
  • 36
  • 132
  • 182

4 Answers4

61

Go to Window->Preferences->Java->Code Style->Formatter. Create new formatter. Click on edit and then pick tab Line Wrapping and set Line Wrapping policy to Do not wrap.

draganstankovic
  • 5,382
  • 1
  • 27
  • 33
  • 3
    thank you(hvala puno), I also had to increase maximum line width it was set to 80 – ant Jul 13 '10 at 23:46
  • 2
    :) Also in Window->Preferences->General->Editors->Text there is an option "show print margin". If you turn it on you'll always see vertical gray line that shows you when to break to a new line. – draganstankovic Jul 14 '10 at 00:01
  • 2
    You have to set the max line width to a very large number, like 1000. The line wrapping policy is only for line with value pair. – SwiftMango Sep 28 '12 at 22:30
5

The default line wrapping in Eclipse is really rather irritating and the main reason why is that the 'line width' is set as 80 characters, clearly a hangover from the nineteen eighties. This really should be updated now that everyone uses high resolution monitors instead of 80 char wide punch cards.

You probably don't want to turn it off entirely but instead you want to change the 'line width' to something more sensible (otherwise when you use the auto formatter you may get lines of code that go on forever).

I would suggest a value of 140, which seems to work nicely for most of us now using 1080p monitors.

In order to do this you need to...


With-in Preferences, navigate to...

> Java
    > Code Style
        > Formatter

You can't edit the default profiles so you have to hit New... and type a name like 'Eclipse 140 Line Width' for your profile and OK.

Then Edit the profile

Change to the Line Wrapping tab

Change the Maximum Line width from 80 to 140.

Then OK your way out.


If you then want to fix up your existing code, select your target code and use the Source > Format menu option.

Oliver Pearmain
  • 19,885
  • 13
  • 86
  • 90
  • 1
    Did he specifically ask how to turn it off? – bobanahalf Jul 31 '19 at 20:04
  • This doesn't answer the question asked, but gives what you think should be done instead. While that's not a bad thing to do in addition to answering the actual question asked, assuming the asker doesn't know what they want isn't a good thing to do. I for example turn off word wrapping in formatters - I prefer to scroll code rather than have line breaks in it. – Andrew Mar 29 '21 at 22:28
  • Everything in eclipse is irritating and not helping, so annoying... – Yesyoor Feb 25 '22 at 12:34
3

In Helios, set 'Line Wrapping/Function Call/Indentation Policy' to 'Indent on Column' for all cases. This seems to stop the pathological case where it splits a line to try and fit within a fixed width but ends up with it further to the right than it would have been unsplit.

Or, as suggested above, disable line wrapping, or set a very wide line width. But I find it better to have it wrap and get it right than not to wrap at all.

soru
  • 5,464
  • 26
  • 30
2

There is an option "never join wrapped lines". This will help to keep our custom wrapping unchanged. Great Feature.

Sancho George
  • 99
  • 1
  • 4