6

I primarily use Netbeans to write PHP code and as an example you can see in this example that my code indentation is horrendous. Pulling this code or push to the code doe not reflect the indentation issues seen here.

That is to say: I can push that the indentation shown in the example are not shown or reflected in the editor and the same goes for pulling.

I have my tabs set to 4 spaces in netbeans, whats going on? how can I fix this? This reflects poorly on me as a developer.

MohitGhodasara
  • 2,342
  • 1
  • 22
  • 29
TheWebs
  • 12,470
  • 30
  • 107
  • 211
  • When I look at your code (by following the link you provide), then the indentation of your code looks beautiful. I use Chrome/Windows7 to view it. – tbsalling Jun 12 '13 at 13:10
  • Im using chrome as well on windows 7 and it looks poorly indented, as in some are 8 tabs in and others are 4. Maybe its just my browser. I assumed it was net beans doing this or github – TheWebs Jun 12 '13 at 15:24
  • Can you pinpoint some exact lines that you think are wrong? Then I shall take a close(r) look and perhaps send you a screen shot. – tbsalling Jun 12 '13 at 15:49
  • 29-316 is all 8 spaces instead of 4 (which I have 4 as the default) 277-293 looks 8 spaces in. 216-218 looks like its out dented away from the comment block same with 198-200. In my editor these are all indented properly. – TheWebs Jun 12 '13 at 17:45
  • Ah yes. I see. It is because e.g. line 215 is indented by a tab; whereas line 216 is indented by 4 spaces. You need to re-indent you whole file using either tabs or spaces. – tbsalling Jun 13 '13 at 06:32

2 Answers2

11

Try this

Visual Studio Code:

  • Open command palette [ctrl + shift + p] > type and select "Convert indentation to spaces"

Sublime Text:

  • Open command palette [ctrl + shift + p] > type and select "convert to space"

Netbeans:

MohitGhodasara
  • 2,342
  • 1
  • 22
  • 29
4

You are mixing tabs and spaces for indention. TAB, ascii character 9, is a different character than Space, ascii character 32. There are two settings your editor has related to using tabs:

  1. How many columns should a tab display as. You have this configured at 4 columns. GitHub displays tabs as 8 columns. That's why things look different.
  2. What does hitting the Tab key do? You can configure your editor to insert either a literal TAB character or some number of spaces when you hit the Tab key.

I won't start a tabs vs. spaces holy war here, but you probably want to use either only tabs or only spaces for indentation. If you use spaces, your code will look the same to everyone. If you use tabs, different people can change the width of a tab in their editor to view the code differently.

Peter Lundgren
  • 8,787
  • 2
  • 26
  • 21
  • Thats the thing, My tabs are set to use 4 spaces, so essentially when I hit tab it indents the code 4 spaces. This is what I set in Netbeans, but seeing that github uses actual tabs how do I fix this across the whole project? – TheWebs Jun 13 '13 at 13:17
  • You need to fix the actual files. Some lines in your file are using tabs and some spaces. Maybe a find/replace tab -> 4 spaces (if you want only spaces). – Peter Lundgren Jun 13 '13 at 20:45
  • Kate editor under KDE, and all other applications using kwritepart KPart for that matter, beautifully displays tab and space on your files. so you can easily see the problem and fix it. – Mathieu J. Sep 05 '15 at 10:39
  • Old thread, but don't forget that if you use tabs for indentation, you should still use spaces for _alignment_ of multi-line constructs, or it's gonna get messed up with different tab width settings anyway. – Oskar Berggren Jul 26 '19 at 12:41