How do I change Eclipse to use spaces instead of tabs?
Java Editor
- Click Window » Preferences
- Expand Java » Code Style
- Click Formatter
- Click the Edit button
- Click the Indentation tab
- Under General Settings, set Tab policy to:
Spaces only
- Click OK ad nauseam to apply the changes.
[Note: If necessary save profile with a new name as the default profile cannot be overwritten.]
Default Text Editor
Before version 3.6:
Window->Preferences->Editors->Text Editors->Insert spaces for tabs
Version 3.6 and later:
- Click Window » Preferences
- Expand General » Editors
- Click Text Editors
- Check Insert spaces for tabs
- Click OK ad nauseam to apply the changes.
Note that the default text editor is used as the basis for many non-Java editors in Eclipse. It's astonishing that this setting wasn't available until 3.3.
C / C++
- Click Window » Preferences
- Expand C/C++ » Code Style
- Click Formatter
- Click the New button to create a new profile, then OK to continue
- Click the Indentation tab
- Under General Settings, set Tab policy to:
Spaces only
- Click OK ad nauseam to apply the changes.
HTML
- Click Window » Preferences
- Expand Web » HTML Files
- Click Editor
- Under Formatting, select the Indent using spaces radio button
- Click OK to apply the changes.
CSS
Follow the same instructions for HTML, but select CSS Files instead of HTML Files.
JSP
By default, JSP files follow the formatting preferences for HTML Files.
XML
XML files spacing is configured in Preferences.
- Click Window » Preferences
- Expand XML » XML Files
- Click Editor
- Select Indent using spaces
- You can specify the Indentation size if needed: number of spaces to indent.
For the default text editor:
- General » Editors » Text Editors »
Insert spaces for tabs
(check it)
For PHP:
- PHP » Code Style » Formatter »
Tab policy
(choose "spaces") - PHP » Code Style » Formatter »
Indentation size
(set to 4)
For CSS:
- Web » CSS » Editor »
Indent using spaces
(select it) - Web » CSS » Editor »
Indentation size
(set to 4)
For HTML:
- Web » HTML » Editor »
Indent using spaces
(select it) - Web » HTML » Editor »
Indentation size
(set to 4)
For XML:
- XML » XML Files » Editor »
Indent using spaces
(select it) - XML » XML Files » Editor »
Indentation size
(set to 4)
For Javascript:
- Javascript » Preferences » Code Style » Formatter » Edit »
Indentation
(choose "spaces only") - Rename the formatter settings profile to save it
For Java:
- Java » Preferences » Code Style » Formatter » Edit »
Indentation
(choose "spaces only") - Rename the formatter settings profile to save it
From changing tabs to spaces in eclipse:
Window » Preferences » Java » Code Style » Formatter » Edit » Indentation
(choose "Spaces Only")