How to use spaces instead of tabs for indentation in Eclipse

Last updated on June 27, 2020 by Dan Nanni

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 WindowsPreferencesJava → "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.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean