Display 4-space indents as tabs, save as 4 spaces? Follow
So apparently some of the files in our projects were coded with 4-space indents while others were coded with tabs (based on developer preference or ignorance I guess), so now it's a bunch more keypresses to navigate around (unless I just click everywhere with the mouse), and using tab causes mixed indents...
Changing the 4-space indents to tabs causes the changes to show in git diff, so it seems without committing the changes throughout the repos, we're forced to either use spaces where they've already been established, or...
Is there some setting in PHPStorm to display ANY type of 4-space indent as a tab, but save as the already-existing 4 spaces (or leave as mixed case if that's how the file is built or edited to)?
Please sign in to leave a comment.
Hi there,
>Is there some setting in PHPStorm to display ANY type of 4-space indent as a tab, but save as the already-existing 4 spaces
There is no such option.
IDE either uses defined code style for current file type ... or it can detect what indents are used in this particular file and use them (not sure how reliable it is though -- it was not that great when it was first introduced so I always keep it disabled since then; plus, I prefer to force single style).
It's in "Settings/Preferences | Editor | Code Style --> Detect and use existing file indents for editing" -- should be enabled by default. See https://www.jetbrains.com/help/phpstorm/2017.1/code-style.html#d366576e148
AFAIK such detection is done on first few lines that start with whitespace .. so if you have PHPDoc or alike on the top of your file (that would usually have a space on 2nd line dues to the nature of such comments formatting) it may set the detection wrong (even if in whole other code yo might be using tabs). At very least that was my understanding of how and why it was failing back then. Have not tested current implementation myself.
P.S.
At the same time there is this ticket still open ( https://youtrack.jetbrains.com/issue/IDEABKL-3594 ) which talks about the same. Not sure if it's just forgotten or I understand it (ticket) in a wrong way .. or misunderstood that aforementioned option...