Changing editor tab width in eclipse 3.5

Viewed 57787

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?

6 Answers

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

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?
Related