How to use spaces instead of tabs for indentation in Eclipse

In Eclipse, you can auto-indent your code, so that your code can be formatted effortlessly. By default, Eclipse inserts 4-space wide tabs for indentation. While no one questions the importance of indentation for clean programming, there's a never-ending debate on whether to use spaces or tabs for indentation. Some folks prefer spaces to tabs or a mix of spaces and tabs, because tabs can be displayed differently on different editors. If you are one of them, here is how to use spaces instead of tabs for indentation on Eclipse.

Go to Windows -> Preferences -> Java -> Code Style -> Formatter on Eclipse menu.

If you have already created a custom Formatter profile rather than using an Eclipse built-in profile, you can click on "Edit" button shown next to the profile that you are using.

If you are using a built-in Formatter profile, you need to create a new profile off of the built-in Eclipse profile. To create a new profile, click on "New" button, as shown below. Once you click on "OK", it will show you a profile editor window.

On the profile editor window, change "Tap policy" from "Taps only" to "Spaces only" under "General settings", as shown below.

Once the new profile is applied and saved, the new indentation policy will be applied to any newly created Java code.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to use spaces instead of tabs for indentation in Eclipse

  1. How to I make it so the new indentation policy (spaces only) will be applied, not just to any newly created Java code, but to any new workspace?

Leave a comment

Your email address will not be published. Required fields are marked *