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?
-
7Tabstops of 5 is really unusual. – Anon. Dec 22 '09 at 20:42
-
4The size of a tab is just an opinion, but actually inserting spaces is the most stupid thing you can do if you ask me. – timing Mar 01 '13 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." https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md – leticia Sep 06 '13 at 20:47
-
5The 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. – Camden S. Jan 20 '14 at 17:52
-
5Isn'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 – Noobification Nov 02 '14 at 13:40
-
I wish I knew what a _real_ tab is ! What you call a 'tab' is a control character that originally was labelled as 'htab' (for horizontal tab) and identified by number x09 in ASCII. In other words, a htab sports no 'size' in itself. It is for the text editor to specify how wide the white space it equates to must be. – Brice Coustillas Jan 06 '17 at 16:04
-
https://www.youtube.com/watch?v=U2PHidyiCWE&feature=youtu.be – Nanhe Kumar Mar 05 '19 at 12:55
-
"Code MUST use 4 spaces for indenting, not tabs" that's one of things I will never understand in PSR... rest is good ;). – Grzegorz Apr 15 '19 at 16:51
5 Answers
Go to Tools-> Options-> Editor-> Formatting and uncheck 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.
You can also change it in a per-project fashion. Right click on the project icon, select Properties and review the Formatting category.
These menu items remain valid as of NetBeans 8.0.

- 142,137
- 41
- 261
- 360
-
7Did uncheck everywhere "Expand tabs to spaces". It's a bug in Netbeans. It will ALWAYS expand to spaces. – openfrog Dec 25 '09 at 10:15
-
3Apparently, 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. – Álvaro González Dec 28 '09 at 09:42
-
30Same 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 Feb 23 '11 at 21:27
-
7@mvds: Great, that works! You could also set "Tab Size" to 4. It just need to be equal with "Number of Spaces per Indent". – PiTheNumber Nov 03 '11 at 15:41
-
Thanks for answering this. I've been working on a collaborative project and the other devs have been getting increasingly annoyed that netbeans is messing up their formatting due to using spaces instead of tabs. But this fixed it so thanks. – Pattle Apr 05 '13 at 23:23
-
This answer seems to be outdated and didn't work for me. grilix answer did work for me. – Omar Tariq May 17 '14 at 10:58
-
For me tabs work only inside the functions/methods, but everywhere else are spaces. Is this a bug in `netbeans` or can it be fixed somehow? – Jo Smo Jul 03 '14 at 12:40
-
1@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! – Jo Smo Jul 03 '14 at 12:43
-
-
@mvds also for me it only worked after following your steps (i.e. both options set to 8, both to 4 didnt work). Maybe you should post it as answer, because without reading your comment I would be still searching for a solution. – 463035818_is_not_an_ai Jan 27 '16 at 16:43
-
In Mac, the link is under: **Netbeans** -> **Preferences...** – Patricio Córdova Mar 01 '16 at 15:41
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] ....

- 5,211
- 5
- 33
- 34
-
-
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 – qed Nov 01 '13 at 09:58
-
Netbeans 8.0 and this answer actually helped me. This should be the correct answer as of 2014. – Omar Tariq May 17 '14 at 10:57
-
1You 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.) – CrazyPyro Jun 03 '14 at 19:32
-
1
-
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.

- 2,961
- 2
- 31
- 57
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.

- 51
- 1
- 1
Netbeans IDE 8.2 (OSX)
Goto File -> Project Properties (Your Project)
Select Formatting in Categories:
Click on Edit global options.
Then Click on Ok
- 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)
Then Click on Ok

- 15,498
- 5
- 79
- 71