Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: Automatic line wrapping to specified width

I'd like for my lines, especially within comments, to be automatically managed so they don't get too long.

I remember once I had a configuration for vim which automatically moved the word I was typing to the next line once I reached 72 characters. It wasn't smart enough to rearrange the paragraph if I edit it, but it was a start.

Is there something that can manage these for me? I have a tendency to write really long comments in my code, and it helps to make them look neat by having consistent width, but it's always a pain to do this because oftentimes editing a sentence requires editing the entire rest of the paragraph.

I have just recently discovered the Ctrl+Shift+F feature. It is amazing and superior to Ctrl+I which is what I was using up till now, but I noticed that it does not do anything to clean up my comments.

Update: The answers are correct when working with Java in Eclipse. It seems like I have to wait for the CDT to incorporate this feature.

like image 216
Steven Lu Avatar asked Feb 11 '12 16:02

Steven Lu


People also ask

How do I change the line wrap in eclipse?

There is a "Toggle Word Wrap" command hidden in the "Window > Editor" menu (default shortcut is Alt+Shift+Y). Or you can use the Quick Access bar: Ctrl+3, and type wrap.

How do I change line width in eclipse?

In preferences Java -> Code Style -> Formatter, edit the profile. Under the Line Wrapping tab is the primary option for line width (Maximum line width:).

How to disable Line Wrapping in Eclipse?

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.


1 Answers

In "Windows -> Preferences", go to "Java -> Code style -> Formatter" to customize the formatter (called when you click Ctrl+Shift+F). In the tab "comment", you can set the maximum line width for comments (it can be different then the line width for code).

Tip: in the preferences, "Java -> Editor -> Save actions", you can make Eclipse to automatically format your file when you save it, so your code is always correctly indented !

like image 84
Baldrick Avatar answered Oct 28 '22 11:10

Baldrick