Changing editor tab width in eclipse 3.5

前端 未结 6 484
眼角桃花
眼角桃花 2020-12-29 17:46

I am trying to adjust the width of tabs from Window -> Preferences -> General -> Editors -> Text Editors where there is a field for \"Display Tab Width\". But no matter what

相关标签:
6条回答
  • 2020-12-29 18:13

    Changing Window -> Preferences -> General -> Editors -> Text Editors tab preference is relevant for text files, not for java files as indicated here. You may create a text file in Eclipse and check that your tab size is really changed.

    0 讨论(0)
  • 2020-12-29 18:13

    This setting is superseded for Java by the setting from the Code Style Formatter.

    It can be found in Java / Code Style / Formatter (click Edit) / Indentation tab / Indentation

    0 讨论(0)
  • 2020-12-29 18:25

    How to set tab size (number of spaces when you press Tab) in Eclipse or Eclipse CDT:

    There are multiple places to check and things to do:

    1. Global Preferences:
      1. Window --> Preferences --> General --> Editors --> Text Editors --> change "Displayed tab width" from 4 to 2
      2. Window --> Preferences --> Java OR C/C++ [depending on which you're using] --> Code Style --> Formatter --> click "Edit" button for your "Active profile" --> click "Indentation" tab on top-left --> change "Indentation size" to 2, "Tab size" to 2, and "Tab policy" to "Spaces only".
    2. Project Preferences (these override the global settings for a given project):
      1. Project --> Properties (or just right-click on project in the folder list at the left, and go to "Properties") --> Java OR "C/C++ General" [depending on what you're using] --> Formatter --> either uncheck the box for "Enable project specific settings", OR check that box and ensure your settings are correct (refer to 1.2 above, beginning with the click "Edit" button step, but do it from this menu this time).
    3. To test your new settings: return to your editor and press Enter with the cursor sitting immediately after an opening curly brace ({) somewhere. It should go to a new line with the proper indentation you've set above.
      1. NB: watch out! If you press Enter on or after a line with different indentation from what you've set above, it will duplicate that wrong indentation (by copying the style of the lines just above) rather than accepting your new indentation settings. Do NOT think it isn't working in this case! It IS working! Just delete all of the old indentation and press Enter right after a { and you'll see everything works just fine.

    Version tested: All tested in Eclipse IDE for C/C++ Developers, Version: Oxygen.3a Release (4.7.3a).

    Duplicate or Related Questions & Answers:

    1. Google search for "Eclipse change tab size" - https://www.google.com/search?q=eclipse+change+tab+size&oq=eclipse+change+&aqs=chrome.0.69i59l3j0l3.2483j0j4&sourceid=chrome&ie=UTF-8
    2. https://superuser.com/questions/462221/how-do-i-reliably-change-the-indentation-width-in-eclipse
    3. Eclipse tab width not changing

    Also Related

    1. Set line width vertical bar marker / print margin - Is there an Eclipse line-width marker?
    0 讨论(0)
  • 2020-12-29 18:27

    Java files have a special place to edit this setting. You need to go to

    Window -> Preferences -> Java -> Code Style -> Formatter

    And edit the profile.

    0 讨论(0)
  • 2020-12-29 18:32

    Check your Java->Code Style->Formatter settings, to see whether you're using tabs or spaces; you might be using spaces!

    0 讨论(0)
  • 2020-12-29 18:32

    After digging into this more deeply, I think I've figured this out:

    Java file tab DISPLAY width

    Confusingly, this is under "Formatter" in preferences (like the accepted answer says). But this is inconsistent location-wise with where the option for tab display width for the non-java file Editor is located.

    /instance/org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.indentation.size=16

    Text file tab DISPLAY width

    /instance/org.eclipse.ui.editors/tabWidth=2


    I emphasize DISPLAY because this is just for rendering in Eclipse. It does not change the contents of your file, and has no effect on "Source -> Format".

    0 讨论(0)
提交回复
热议问题