Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm will not use 2 spaces for indents

Tags:

phpstorm

I'm sorry, I know this has been asked before, but the other answers are not doing anything for me.

PhpStorm keeps using 4 spaces for indents, and it is driving me mad. The file is a .php file, and all the settings I know of are correctly set. I have checked these things:

1.) Editor | Code Style | 'Detect and use existing file indents' is not checked (and the file uses 2 spaces anyway)

2.) Editor | Code Style | PHP | 'Tab size' & 'Indent' are set to 2 spaces

3.) I have restarted PhpStorm

4.) I have closed and reopened the file.

5.) My PhpStorm is the most recent version, 2016.3.2

6.) There is only one .editorconfig in the path of the file, and here are its contents:

# Drupal editor configuration normalization
# @see http://editorconfig.org/

# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[composer.json]
indent_size = 4

I have also tried removing the last two lines, just out of paranoia, and after restarting PhpStorm again, it did nothing.

like image 336
RaisinBranCrunch Avatar asked Sep 11 '25 17:09

RaisinBranCrunch


1 Answers

As it turn out it's a bug in PhpStorm:

"Tab size" value is ignored if php file isn't started with <?php i.e.:

#!/usr/bin/env drush
<?php

For those who are interested here is a ticket on PhpStorm's Issue Tracker: https://youtrack.jetbrains.com/issue/WI-34735 -- watch it (star/vote/comment) to get notified on any progress.

Also for newer IDE versions, check if .editorconfig config-file exists (in any directory of directory-chain leading to your script-file), because Settings from said config-file have higher priority, and will overwrite your IDE settings.

like image 100
LazyOne Avatar answered Sep 13 '25 14:09

LazyOne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!