Eclipse auto-formatter, disable auto line-wrapping of comment lines

Gal picture Gal · Mar 10, 2012 · Viewed 16.5k times · Source

I love eclipse auto formatting, but there's one feature that's driving me raging mad:

Since I use wrap-lines in my auto-formmatter, code like this:

private static Location                         _location           = null; // this is a comment

turns into horrible, horrible code like this:

private static Location                         _location           = null;                 // this
                                                                                                    // is
                                                                                                    // a
                                                                                                    // comment

this is not only painful to watch, but not at all convenient to change back...

Is there any way to remove line-wrapping for comments, or at least fix so it doesn't look like an absolute mess?

Thanks

Answer

Boris Strandjev picture Boris Strandjev · Mar 10, 2012

I think that the thing you are specifically asking about you can achieve by editing your formatter:

  • Window -> Preferences -> Java -> Code Style -> Formatter. There edit you click on Edit...
  • If you are using the default Eclipse formatter you will need to edit the profile name (you cna not edit built in profile).
  • Go to comments
  • Deselect line comment formatting.

That way no formatting of comments of the type // will be done.