score:1282
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.
score:0
In eclipse mars (EE) on Mac OS X, the only way I could find this in the preferences was to open the Preference dialog and type Formatter, then select Java->Code Style->Formatter.
Java->Code Style has no access to Formatter!
score:0
And don't forget the ANT editor
For some reason Ant Editor does not show up in the search results for 'tab'
or 'spaces'
so can be missed.
Under Windows > Preferences
- Ant » Editor » Formatter »
Tab size:
(set to 4) - Ant » Editor » Formatter »
Use tab character instead of spaces
(uncheck it)
score:0
- Click Window » Preferences
- Expand Java » Code Style
- Click Formatter
- click new
- Select the profile name
- Click ok
- Click the Edit button
- Click the Indentation tab
- Under General Settings, set Tab policy to: Spaces only
- Click OK.
score:0
As an augmentation to the other answers, on Mac OS X, the "Preferences" menu is under Eclipse, not Window (unlike Windows/Linux Eclipse distributions). Everything else is still the same as pointed out by other answers past this point.
IE: Java Formatter available under:
Eclipse > | # Not Window!
Preferences > |
Java > |
Code Style > |
Formatter |
From here, edit the formatter and the tab policy can be set under "Indentation".
score:1
Also consider using an .editorconfig file: https://marketplace.eclipse.org/content/editorconfig-eclipse. Someone not using Eclipse may also benefit from this, in the worst case it can serve as a guideline. NOTE: I will not enter the tabs vs space wars but use spaces FTW :-)
score:1
You can definitely use XML file to configure your formatter of the coding style. The formatter file helps you to have the same coding style and guidelines across your team members.
Adding these below setting variables would have a tab= 2 spaces
and convert to space even you probably use Tab
shorthand key when coding using Eclipse.
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="yes"/>
Best,
score:3
Don't miss Tab policy for both of * Spaces only * Use spaces to indent wrapped lines
I checked only the latter thing and left the Combobox as Tabs Only which kept failing CheckStyle.. FYI, I'm talking about Preferences > Java > Formatter > Edit...
score:4
In Eclipse go to Window » Preferences then search for Formatter.
You will see various bold links,
click on each bold link
and set it to use spaces
instead of tabs
.
In the java formatter link, you have to edit the profile
and select the tab policy, spaces only
in indentation tab
score:4
Window->Preferences->Java->Code Style->Formatter->Edit->Indentation = "Spaces Only"
score:4
In eclipse format xml:
For tab:
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
For space:
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
score:6
Be sure to check the java formater since it overwrites the "insert spaces for tabs" setting. Go to:
Java->Code Style"->Formatter->Edit->Identation
Note: you will need to create a custom format to be able to save your configuration.
score:6
Eclipse IDE for C/C++ Developers, Version: Helios Service Release 2
You need to create new profile by pressing New button inside "Window->Preferences->Code Style"
Go to Indentation tab and select "Tab policy = Space only"
Eclipse IDE for C/C++ Developers, Version: Kepler Service Release 1
Follow the path below to create new profile: "Window > Preferences > C/C++ > Code Style > Formatter"
Go to Indentation tab and select "Tab policy = Space only"
score:6
I found the solution this problem very simple and which works always. It is change the eclipse setting file.
For example (change HTML indentation size):
- Found
org.eclipse.wst.html.core.prefs
file which should be inyour_workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/
- Add/Change to line in file:
indentationChar=space
indentationSize=4
score:8
Go to Window -> Preferences and type tab as the search text (which will display a dialog like below):
Go to the highlighted sections to change the tab policy. For the Editor settings it is mostly Indent using spaces (also shown above).
For Formatter settings you need to edit the active profile and update Tab policy (available under `Indentation -> General settings:
score:10
When I faced this problem I had "use spaces for tabs" set to true everywhere I could find, and yet I was still getting tabs. It ended up being because tabs were used elsewhere in the file and it was trying to do smart indentation or something frustrating.
It was resolved by selecting the entire contents of the file and pressing, on a mac, command+shift+f
. This applies the given formatting to a file. I do not know the same keybinding on windows, but give that a try. At that point I begin getting the expected behavior.
score:22
For Default Editor:
Window » Preferences » Editors » Text Editors » Insert spaces for tabs
For Java editor
Window » Preferences » Java » Code Style » Formatter » Edit » Indentation » Tab policy
"Spaces Only"
score:24
Just a quick tip for people stumbling across this thread; there is one more place where this setting can also be set, in your project!
Eclipse supports project-specific settings, and some projects will use their own, un-managed tabs/spaces settings, which won't show up anywhere except the current project Properties.
This can be managed through:
- Right-Click current Project in Package Explorer
- Properties » Java Code Style
- Turn off all the project-specific options
This will generally only be an issue if you import someone else's code into your Eclipse.
score:27
For CDT:
- Go to Window/Preference » C/C++ » Code Style » Formatter » New
- Create a new one because the built in profile can not be changed
- MyProfile (choose one name for the profile)
- Indentation »
Tab Policy
(choose Spaces only)
score:38
From changing tabs to spaces in eclipse:
Window » Preferences » Java » Code Style » Formatter » Edit » Indentation
(choose "Spaces Only")
score:155
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
Source: stackoverflow.com
Related Query
- How do I change Eclipse to use spaces instead of tabs in Javascript editor?
- How do I change Eclipse to use spaces instead of tabs?
- How to I edit the default "formatter profile" in eclipse neon? (wanting to use spaces instead of tabs for all code types)
- How can I get Eclipse to insert tabs instead of spaces for Java content assist?
- How to get spaces instead of tabs in eclipse
- How to tell PHPEclipse to use spaces instead of tabs
- What causes imported Maven project in Eclipse to use Java 1.5 instead of Java 1.6 by default and how can I ensure it doesn't?
- How to get rid of the warning: Use '$' instead of '.' for inner classes in Eclipse
- Eclipse multi-line indent uses tabs instead of spaces (pydev)
- How to deny maven to use open projects in Eclipse instead of jar from repository
- Eclipse indents new line with tabs instead of spaces
- How can I set Zend Studio 10.0.1 to use Spaces for Tabs in PHP files?
- How to set Eclipse CDT to use GCC-4 instead of GCC?
- How to install "JavaSpider" plug-in (by Eric Gamma) in the modern Eclipse environment or what to use instead of it?
- Spaces instead of tabs in Eclipse (Galileo 3.52)?
- how to use javac instead of javah for creating c++ JNI header using Eclipse
- How to use Java console in eclipse to change string
- How to keep spaces from becoming tabs in Eclipse (w/ PyDev)
- How to force Eclipse to use g++ instead of gcc?
- Eclipse spaces instead of tabs for aligning variable names and values, how?
- How to get eclipse to use cocos console instead of build-android.py?
- How to configure an Eclipse Java format to use two spaces after a sentence in comments?
- How to change font size in Eclipse for Java text editors?
- Eclipse says: “Workspace in use or cannot be created, chose a different one.” How do I unlock a workspace?
- How to change the Eclipse default workspace?
- How to change the value of ${user} variable used in Eclipse templates
- How to change an Eclipse default project into a Java project
- How to configure Eclipse build path to use Maven dependencies?
- Eclipse "Server Locations" section disabled and need to change to use Tomcat installation
- How can I change Eclipse theme?
More Query from same tag
- Copying eclipse projects through command line?
- Missing Project in the Java Build Path - Projects settings
- Hardcoding Strings in Eclipse
- How do I install/enable OpenMP for Eclipse with MinGW on Windows?
- How can we ignore metadata (SVN properties changes) diff while creating/applying patch in eclipse?
- How to instantiate org.eclipse.jdt.core.ICompilationUnit or org.eclipse.core.internal.resources.Workspace?
- Deploying libraries in Web Fragment projects in Eclipse
- Can formatting a Spock Specification be controlled in Eclipse/STS?
- StreamSupport collector and java 7
- Can't connect Tomcat 6 and oracle 10g XE for jsp database connectivity
- Not getting response from controller in Spring MVC when using ajax
- Developing Eclipse RCP with IntelliJ
- android Compilation error "An error has occurred. See error log for more details. com.android.ddmlib.IDevice.getName()Ljava/lang/String;"
- Eclipse CDT open declaration of auto type variable
- Imported class files are shown under default package in Eclipse, how can i access them?
- Eclipse autocomplete change variable names
- Eclipse not working - missing Java
- Unable to deploy Android app thru IBM Worklight
- Change folder name in webapp when deployin in Tomcat from Eclipse
- Android program fails. No errors, no log cat. No clues
- How to create separate library for include in C++/Eclipse
- Unable to install IBM Worklight plugin in Eclipse ADT
- Create new android application project in Eclipse
- "Failed to open X display" when trying to run project from within Eclipse
- JAR file Error when open it
- Having issue launching Eclipse on Feodra 24
- 414 URI too long with Apache Tomcat Eclipse
- Running a multi-module Maven web app in Eclipse
- Modifying AndroidManifest.xml with build tag causes infinite rebuilding in Eclipse
- artifact:pom command not recognized in one workspace but not another