How do I change Eclipse to use spaces instead of tabs?
I often post about Eclipse on Twitter. Follow me here Follow @readlearncode
By default Eclipse indents code with a tab character this configuration can be changed to use spaces from the preferences under the window menu option.
You will see the option to create a new profile.
Click the new button and enter a name for the profile in the dialogue box that pops up. Use the Eclipse [built-in] profile to initialize your new profile. The profile editor dialogue box will pop-up as follows:
From within the Indentation tab of this dialogue box select “Spaces only” option from the Tab policy drop-down. You can also select the number of space to insert. Here the default is set to four.
To change the default for the text editor do the following:
Tick the check box labelled "Insert spaces for tabs"
There is one more place where this could also be set. Eclipse supports project-specific settings, and some projects will use their own configurations. These will only show up in the current project properties.
These settings can be accessed as follows:
Right-click on the current project->Properties->Java Code Style->Turn off all the project-specific options
This will only be an issue if you have imported someone else’s project.
These instructions are relevant for the Kepler version of Eclipse but should also be relevant for a previous and future version of Eclipse.
If you are using Spring Source Tool Suite (STS) you will find the configuration options in the same place.