Indentation with spaces and the tab key in Eclipse (3.5 aka Galileo)

28 May, 2010 - 00:29
Categories:

Indentation with spaces and the tab key in Eclipse. I've pulled quite some hair on this one and now that I found the solution, I decided to write it down, so I don't have to loose my precious hair anymore.

Everybody has its own preferences, but I like 2 space indentation for PHP (code style of Drupal) and 4 space indentation in Python. And when I press the tab key, I want to increase the indentation level, not insert a tab character. Doesn't seem like much to ask, but it took a long and frustrating process to get this working in Eclipse (3.5 aka Galileo at the time of this writing), Aptana Studio actually, with PDT for PHP development and the excellent Pydev for Python development.

There are lot of tab/indentation related options scattered around in the preferences and apparently you have to be careful about how you set them up.

First important thing: do not enable the "insert spaces for tabs" option under Preferences/General/Editors/"Text Editors". Enabling this one interferes rather aggressively with the other tab/indentation settings.

 disable general tab handling

For PHP, I set the indentation policy to two spaces under Preferences/PHP/"Code Style"/Formatter and enabled "Tab key indents the current line" under Preferences/PHP/Editor/Typing

 2 space indentation

 tab key indents

For Python, the settings are on one page under Preferences/Pydev/Editor: set the tab length and enable "Replace tabs with spaces when typing".

 4 space indentation with tab

Now back to coding (as long as the tools don't get in the way again).

16 September, 2011 - 19:56

THANK YOU!!! That is an EVIL

Anonymous (not verified)

THANK YOU!!! That is an EVIL OPTION. Wasted so much of my time. appreciate the help :-D

30 May, 2011 - 10:06

great piece of information

András Szepesházi (not verified)

Thanks mate, you made my day. I recently had to switch to spaces from tabs as per project policy. I used the "insert spaces for tabs" option, as I'm sure many others did so. With that, I lost the ability to unident code blocks, which sucked great time. Setting up the editor your way, everyhing works as charm.

Thanks again for sharing this!

3 December, 2010 - 14:23

Thank you

Anonymous (not verified)

The "evil" checkbox was stumping me. All is well now.

24 June, 2010 - 00:12

Thanks for the information.

Chanda Patel (not verified)

Thanks for the information. It helped me a lot !

28 May, 2010 - 15:04

Similar in Sigasi's VHDL plugin

Hendrik (not verified)

I have to admit that our VHDL plugin for Eclipse (Sigasi HDT) also ignores the tab settings in the general editor preferences and uses its own settings.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.

More information about formatting options