Changing editor tab width in eclipse 3.5

EclipseTabs

Eclipse Problem Overview


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 I enter there the size of indentations when I start a newline in a Java file is 4. Any ideas?

Eclipse Solutions


Solution 1 - Eclipse

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.

Solution 2 - Eclipse

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.

Solution 3 - Eclipse

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

Solution 4 - Eclipse

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

Solution 5 - Eclipse

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.

Text file tab DISPLAY width


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".

Solution 6 - Eclipse

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:
  2. Window --> Preferences --> General --> Editors --> Text Editors --> change "Displayed tab width" from 4 to 2
  3. 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".
  4. Project Preferences (these override the global settings for a given project):
  5. 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).
  6. 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.
  7. 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).

  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. https://stackoverflow.com/questions/14681954/eclipse-tab-width-not-changing
  1. Set line width vertical bar marker / print margin - https://stackoverflow.com/questions/1248895/is-there-an-eclipse-line-width-marker/49372370#49372370

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNeilView Question on Stackoverflow
Solution 1 - EclipseNeilView Answer on Stackoverflow
Solution 2 - EclipseirudyakView Answer on Stackoverflow
Solution 3 - EclipseJonathan FeinbergView Answer on Stackoverflow
Solution 4 - EclipseDavid PierreView Answer on Stackoverflow
Solution 5 - EclipseSridhar SarnobatView Answer on Stackoverflow
Solution 6 - EclipseGabriel StaplesView Answer on Stackoverflow