122

When I hit Tab for indenting code, I like to get a real tab. Meaning that when I select that, I only have one large thing selected. NetBeans inserts 5 spaces instead of a tab when I hit Tab. Is there a way I can change that?

8
  • 7
    Tabstops of 5 is really unusual. Commented Dec 22, 2009 at 20:42
  • 4
    The size of a tab is just an opinion, but actually inserting spaces is the most stupid thing you can do if you ask me. Commented Mar 1, 2013 at 13:18
  • 11
    "Using only spaces, and not mixing spaces with tabs, helps to avoid problems with diffs, patches, history, and annotations. The use of spaces also makes it easy to insert fine-grained sub-indentation for inter-line alignment." github.com/php-fig/fig-standards/blob/master/accepted/… Commented Sep 6, 2013 at 20:47
  • 5
    The PSR-2-coding-style-guide says "Code MUST use 4 spaces for indenting, not tabs." as the previous commenter mentioned. It's just good to be aware when you're diverging from standards. Commented Jan 20, 2014 at 17:52
  • 5
    Isn't the PSR standard for PHP? Why does netbeans force it on everything? Tab is more natural and intuitive.... you use space for space and use tab for indenting Commented Nov 2, 2014 at 13:40

5 Answers 5

162

Go to Tools-> Options-> Editor-> Formatting and uncheck Expand tabs to spaces:

Expand Tabs to Spaces

Ensure you also pick coherent values for "Number of Spaces per indent" and "Tab Size".


Additionally, you can check all the items in the Language combo and make sure they all use the general setting.

Use All Languages Setting

You can also change it in a per-project fashion. Right click on the project icon, select Properties and review the Formatting category.

Use project specific options

These menu items remain valid as of NetBeans 8.0.

Sign up to request clarification or add additional context in comments.

11 Comments

Did uncheck everywhere "Expand tabs to spaces". It's a bug in Netbeans. It will ALWAYS expand to spaces.
Apparently, it doesn't alter previous spaces. It only affects lines where you change the indentation. Is that the case? You can try the "Source-> Format" command.
Same issue here but I think I've got it: If your current file has "space indents" at some odd distance (like 3, 5, ...) then NetBeans will try to be clever and indent to that level using spaces if you hit tab. Set both tab stop and number of spaces per indent to 8, then Source->Format as Alvaro mentioned, and then you get the tab key to insert.. a tab.
@mvds: Great, that works! You could also set "Tab Size" to 4. It just need to be equal with "Number of Spaces per Indent".
@mvds your method worked! I just had to set the "number of spaces per indent" and the "tab size" to the same value and it worked! Both to 4 or both to 8. Thanks!
|
71

It seems to work if you select the same value for "Number of Spaces per Indent" and "Tab Size", after unchecking the "Expand Tabs to Spaces" Option, in Tools -> Options -> Editor -> Formatting, for example:

 [ ] Expand Tabs to Spaces Number of Spaces per Indent: [ 4] Tab Size: [ 4] .... 

6 Comments

This is also solution for 7.3 version (MAC)
By the way, if you have jVi installed, these options should be set through jVi config, standard options for tabwidth and shiftwidt will not work anymore
Netbeans 8.0 and this answer actually helped me. This should be the correct answer as of 2014.
You may also need to have "All Languages" selected in the Language dropdown in order for the tabs options to be visible. (If I have a Python file open, it defaults to the the Python language-specific settings.)
I can confirm that this method works in Netbeans 8.0!
|
7

For NetBeans 7.1.2,

I needed to go to Tools -> Options -> Editor -> Expand Tabs to Spaces and uncheck that one (make sure you have "All Languages" selected). And also put an "8" for both Number of Spaces per Indent and Tab Size.

Just having the same value there does not do the trick for me. It must be 8.

Comments

5

In Tools-> Options-> Editor-> Formatting Expand tabs to spaces should be unchecked and Number of Spaces per Indent should be equal with Tab Size. Also check when you change Language from All languages to other there Override Global Options should be unchecked, too.

Comments

1

Netbeans IDE 8.2 (OSX)

Goto File -> Project Properties (Your Project)

enter image description here

Select Formatting in Categories:

enter image description here

Click on Edit global options.

enter image description here

Then Click on Ok

enter image description here

  • Uncheck : Expand tabs to space.
  • Click on : Apply
  • Click On : Ok

If you want set project specific then :

  • Select : Use project specific options.
  • Uncheck : Expand tabs to space.
  • You can also select Language (PHP)

enter image description here

Then Click on Ok

1 Comment

Also useful for Netbeans 12 :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.