Eclipse: Automatic line wrapping to specified width

22,348

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 !

Share:
22,348
Steven Lu
Author by

Steven Lu

Play a multitouch HTML5 Tetris clone -- http://htmltetris.com (Interesting note about this site. It used to be my site, then Tetris Co. sent me a cease and desist, then I forgot about it, and now it’s back: someone brought it back and put MY code back on the site.) A huge fan of tmux and vim.

Updated on July 22, 2022

Comments

  • Steven Lu
    Steven Lu almost 2 years

    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.

  • Steven Lu
    Steven Lu over 12 years
    So I am using the CDT since I write C++ and not Java. There's no option there that does this.
  • Steven Lu
    Steven Lu over 12 years
    Maybe it's still to be implemented? dev.eclipse.org/mhonarc/lists/cdt-dev/msg22612.html
  • Line
    Line about 7 years
    "Never join lines" was also helpful in this case ;)