Search code examples
javaeclipseformattingformatautoformatting

Eclipse doesn't split string at line width when formatting


I'm currently working on an application in Eclipse where I'm running a really huge SQL statement that spans about 20 lines when splitting it in notepad to fit on the screen. Thus I want the string for the query also to be formatted somewhat more readable than a single line. All the time autoformatting normally worked when I used Eclipse but somehow now neither Ctrl + Alt + F nor rightclicking and selecting the "Format" option from the menu doesn't work to get a line break after a certain amount of characters.

I already checked the preferences where I already tried running my own profile with 120 and 100 characters line width but that didn't fix anything so far. I really don't know why Eclipse won't let me format this anymore. Normally Eclipse would be splitting the string into several lines in this case but I don't really know why this doesn't work anymore.

However other formatting is being fixed when executing autoformatting (e.g. if(xyz){ still becomes if (xyz) {.

Thank you for your help in advance.


Solution

  • As far as I can tell, autoformat as you described was never supported (at least as far back as 2008). And I have been using Eclipse much longer than that

    You can do one of several things.

    • Simply insert the cursor in the string and hit a return.
    • Toggle word wrap Alt-Shift-Y
    • Try writing a regex to do what you want(not certain if this will work).