News Ticker

How do I change Eclipse to use spaces instead of tabs?

I often post about Eclipse on Twitter. Follow me here

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.

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

You will see the option to create a new profile.

Formatter

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:

Profile Editor

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:

Window->Preferences->Editors->Text Editors->Tick the check box labelled "Insert spaces for tabs"

Text Editor

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

Specific Project Settings

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.

I often post about Eclipse on Twitter. Follow me here

Leave a Reply

%d bloggers like this: