Eclipse (ctrl+shift+f) does nothing

13,639

Solution 1

I don't understand why it wouldn't format the code with CTRL + SHIFT + F by try selecting the whole document with CTRL + A) and then using CTRL + I to format the document. You may have the same problem though.

Solution 2

I also encountered this problem. And I figured out the reason by luck.

I am using IBus input method, and when IBus in Chinese mode, Ctrl+Shift+F does not format Java source code in Eclipse Java project. When I changed IBus to English mode, that shortcut works just fine.

Solution 3

Check the followings:

  1. The chosen active formatter profile is exactly what you want(You can find it in Preferences->Java->Code Style->Formatter)
  2. The code lines which needs to format is selected correctly
  3. And the most important one is not to have any syntax error in the file which is formatting

Solution 4

Check for weird syntax in your file. In my case, I had a method with an underscore parameter name:

@Deprecated
public synchronized void setParseMaxDigits(int _) {}

I had to delete sections of my file until I pinpointed that this was the function causing SHIFT+CTRL+F to not format the file. As soon as I changed the above method to,

@Deprecated
public synchronized void setParseMaxDigits(int unused) {}

then SHIFT+CTRL+F started working again.

Share:
13,639
Reggie
Author by

Reggie

Updated on June 05, 2022

Comments

  • Reggie
    Reggie almost 2 years

    I made a new Java file in Gedit.

    When I open it in Eclipse (CTRL + SHIFT + F), it does not format the code.

    (CTRL + SHIFT + F) still formats other Java files (which I also did not create in Eclipse), and it even formats individual lines of code in this particular file when I press (enter) at the beginning of a line.

    It just will not format the entire file with (CTRL + SHIFT + F). I restored defaults in:

    Window > Preferences > General > Keys

    But still nothing. I have installed no plugins.

    Any idea why Eclipse isn't recognizing the file as something that should be formatted when I use CTRL + SHIFT + F?

  • Reggie
    Reggie almost 10 years
    It is in a Java source folder. Eclipse formats the other Java files in this folder just fine.