views:

8199

answers:

3

By default eclipse indents with a hard tab character, how do I change it to spaces?

+4  A: 

From here: http://blog.dotkam.com/2007/03/21/changing-tabs-to-spaces-in-eclipse/

Window->Preferences->Java->Code Style->Formatter->Edit->Indentation = "Spaces Only"

Brian Deacon
+20  A: 

For the Java editor it's as Brian mentions:

Window->Preferences->Java->Code Style->Formatter->Edit->Indentation = "Spaces Only"

However, for the default text editor:

Window->Preferences->Editors->Text Editors->Insert spaces for tabs

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.

Dave Ray
For those who have MyEclipse installed or any other IDE built on top of Eclipse, you may have another editor overriding your settings. This was the case for MyEclipse and JavaScript. I had my "Insert spaces for tabs" setting enabled in Text Editors, but tabs were still being used instead of spaces. I was about to call it a day and write it off as a bug, but then I saw a second editor for JavaScript (*.js ) files in the "Associated Editors" list.
John
This might be a helpful hint, but if you experience the same behavior, check if the file has any other associated editors because they may be overriding your settings. To do so, goto Window > Preferences > General > Editors > File Associations > then look for the file extension which is ruining your day in that list > click it and look at the Associated Editors list below
John
For JavaScript, I saw both Text Editor and MyEclipse JavaScript Editor which was flagged as the default. So one of two things can be done here, you can either set Text Editor to be your default or you can update the MyEclipse JavaScript Editor settings. I opted to do the latter and went to: Window > Preferences > MyEclipse > Files and Editors > JavaScript > Code Style > Formatter > Edit... > Tab policy:Hope this helps!
John
For XML I had no associated edotor but I had to go to Window > Preferences > XML > XML Files > Editor
Bill Comer
+1  A: 

Check also java formater, since it overwrite "Insert spaces for tabs" settings. Go to "Java->Code Style"->Formatter->Edit->Identation"

But beware since you will need to create a custom format to be able to save your configurarion.

ricardo rivaldo