How to customize Eclipse's text editor code formatting
Asked Answered
C

3

24

How can I set my Eclipse's code formatter to allow code rows longer than 80 characters. I know that very long lines is hard to read but in my opinion 80 characters per line is very small value for wide screen monitors.

Constitute answered 24/11, 2009 at 13:52 Comment(1)
Note: starting Eclipse Mars 4.5 M1 (August 2014), the default line length in Eclipse is 120 (instead of 80). See my answer belowTuberculin
P
57

In Preferences, go to Java > Code Style > Formatter and edit/create the formatter and go to tab Line Wrapping. There in you can set the Maximum line width.

Further on you can in General > Editors > Text Editors also set the Print margin column which should shift up that margin (a 1px wide vertical line in the right side of your code) to the desired position. This however doesn't affect the formatter, only the human eye.

Pete answered 24/11, 2009 at 13:55 Comment(1)
Note that the Java editor (at least in Eclipse Neon) uses only the setting in the Code Style formatter for the print margin, overriding the setting in General -> Editors -> Text Editors. All other editors use the General -> Editors -> Text Editors setting.Cyclometer
S
8

This answer was a bit old, and the path have changed with new versions of Eclipse.

To set the Maximum line width, go to Project > Properties. In the Properties window, go to Java Code Style > Formatter. Select your Active Profile (let the one which is already selected, this is the one you are currently using) and click on Edit. In the tab Line Wrapping, you can set the Maximum line width (80 by default). You can also go to the tab Comments and uncheck Enable Line Comment Formatting if you want your comments not to be formatted on multiple lines with Ctrl+Shift+F.

Don't forget to change the name of the Profile Name; if you don't change it, you won't be able to save your changes (provided the one you are editing is Built-In

Also, you can set the Print margin column in Window > Preferences > General > Editors > Text Editors.

Shennashensi answered 5/3, 2013 at 10:22 Comment(0)
T
8

Regarding the "small" value (80), this has just changed (in August 2014).
See "Eclipse is not a terminal anymore – Default line size of Java code formatter is now 120"
(By Lars Vogel)

Project > Properties, Java Code Style > Formatter.

Edit tab Line Wrapping

A three-years old issue is finally addressed:
bug 356851: Default line size of Java code formatter should be increased to 120

It is not mentioned in the Eclipse Project 4.5 (Mars) M1 - New and Noteworthy, but it is still "Verified for 4.5 M1 using I20140804-2000 build".

Tuberculin answered 11/8, 2014 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.