Duck Dodgers
Duck Dodgers

Reputation: 3461

How to get spaces instead of tabs in eclipse

After doing a little research, I found out that eclipse hides its settings in multiple levels. So, I think, I got all the levels covered here.

Here I have set eclipse to insert spaces instead of tabs. And eclipse even acknowledges there that I have indeed set it up to insert 4 spaces instead of a tab (See the text under Tabulators: it says, "The current indentation size is 4, using spaces"). Tab Settings for C/C++

Then for the general text editor, I have also set it up to insert spaces instead of the tabs. General Tab Settings

And eclipse couldn't have gotten things more wrong even if it had tried!

  1. Unfortunately, despite all those settings, when I press tab, eclipse inserts 2 spaces. Then, I press tab again, and it inserts 2 spaces. Why 2 spaces? Are there still more hidden settings somewhere?

  2. Anyways, this broken system works a bit, until I have one level more of indentation, for example, for a for-loop or an if-block. If I press, tab again, instead of adding 2 more spaces, it converts the 6 spaces into a tab.

  3. And a tab which is not even 4 spaces wide, but instead a tab which looks like a 6- or 8-spaces wide tab.

  4. Ctrl + I also adds tabs, not spaces.

The formatter is also setup as @Neuron suggested in his answer. Formatter

So, where else is eclipse hiding more settings? 2nd level indentation is automatically TAB

Upvotes: 3

Views: 431

Answers (1)

Neuron
Neuron

Reputation: 5813

I fixed it by going to..

Window ⟶ Preferences ⟶ C/C++ ⟶ Code Style ⟶ Formatter

There you need to edit the currently set profile. Click "Edit..." (top right-ish). Now go to Indentation (already open) ⟶ General Settings ⟶ Tab Policy and change this from "Tabs only" to "Spaces only".

If you still have the default profile, give your profile a new name.

Why is this so weird and convoluted? I don't know.

Upvotes: 1

Related Questions