Stop eclipse from line wrapping?

Craig P. Motlin picture Craig P. Motlin · May 21, 2009 · Viewed 35.3k times · Source

Is there a way to get eclipse to stop erasing existing line breaks? If I have a method signature like this, I can't figure out how to get eclipse to leave it alone:

void foo(
    int arg1,
    int arg2,
    int arg3,
    int arg4)
{
    // ...
}

With various settings it will either collapse the arguments down to one line, or wrap them at some margin like this:

void foo(
    int arg1, int arg2,
    int arg3, int arg4)
{
    // ...
}

With "Wrap all elements, every element on a new line" it does preserve this whitespace, but it will ALWAYS wrap, which isn't what I want. I'd like eclipse to apply formatting for indentation and braces and such, just without ever deleting (or inserting) any line breaks.

Answer

VonC picture VonC · May 21, 2009

The formatting of arguments is an old subject, but the one new formatting feature introduced in 3.5 is:

  • eclipse3.5M4 "Formatter option to preserve user line breaks"

The Java code formatter can now optionally preserve user line breaks by not joining lines in code or comments.

For example, the wrapped lines of the return statement in following test case:

before
Example of Code to Format

will be preserved by the formatter when the "Never Join Lines" preference is used, and now produces the following result:

after
Coded Formatted with Never Join Lines

This preference can be configured on the Java > Code Style > Formatter preference page. See the Never join lines option on the Line Wrapping and Comments tab.

That may help, but otherwise there is not much new features on that front in 3.5.