32

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

Gal
  • 5,338
  • 5
  • 33
  • 55

2 Answers2

53

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.

Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • This option doesn't seem to exist anymore in the current version of Eclipse (4.14.0) – Kira Resari Aug 12 '20 at 07:01
  • It still exists. "Format line comments" checkbox. Unfortunately, it doesn't prevent inline comments from being pushed down on the next line, so it's not much use actually. – Ilya Oct 06 '22 at 14:01
2

This annoys me also. To fix the wrapped comments you can use the keyboard shortcut CTL+ALT+J to join the comments onto one line. The comment-indicator characters (// or *) will still be there but at least it will save you some steps. Then you can just run a find and replace for the comment-indicators.

David
  • 101
  • 5