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.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Dan Nanni (see all)
- How to install Suricata intrusion detection system on Linux - September 3, 2015
- How to switch from NetworkManager to systemd-networkd on Linux - August 31, 2015
- How to set up a system status page of your infrastructure - August 25, 2015