The default .editorconfig forces 4-space indentation in Zed
Description
What steps will reproduce the problem?
- Create a new Yii2 Basic Application using Composer:
composer create-project --prefer-dist yiisoft/yii2-app-basic basicOpen the newly created project in Zed.
Configure Zed to use 2 spaces, for example in
.zed/settings.json:
{
"tab_size": 2,
"hard_tabs": false,
"auto_indent": "syntax_aware"
}- Open a PHP file and press
Tab.
Despite the Zed configuration specifying 2 spaces, indentation is inserted using 4 spaces.
Expected behavior
The editor should use the configured 2-space indentation.
Actual behavior
PHP files use 4-space indentation.
This can be particularly confusing because the Zed configuration appears to be correct, and the behavior also occurs when no formatter is configured.
For example, setting:
"formatter": nullprevents formatting entirely, but pressing Tab still inserts 4 spaces.
Cause
The Yii2 Basic Application template includes this .editorconfig:
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.js]
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[*.php]
ij_php_space_before_short_closure_left_parenthesis = false
ij_php_space_after_type_cast = true
[*.yaml]
indent_size = 2
[*.yml]
indent_size = 2
[*.xml.dist]
indent_size = 2
[LICENSE*]
indent_style = unset
indent_size = unsetThe important part is:
[*]
indent_size = 4There is no PHP-specific indent_size, so PHP inherits the global value of 4.
Changing it to:
[*]
indent_size = 2immediately fixes the indentation behavior in Zed.
Why this is confusing
The Yii2 project also includes JetBrains-specific ij_php_* settings, which suggests that this file is primarily intended to provide editor configuration for the project.
However, .editorconfig is also consumed by editors such as Zed. Therefore, the global:
indent_size = 4can silently override the user's expected editor indentation.
In my case, this resulted in several hours of troubleshooting because the Zed configuration itself was correct.
Possible solution
Consider either:
- documenting that the Yii2 template intentionally uses 4-space indentation and that
.editorconfigwill override editor-specific indentation settings, or - adding a PHP-specific setting if the intended PHP indentation differs from the global setting, or
- reconsidering whether the default
.editorconfigshould impose a specific indentation size on all editors.
At minimum, it would be helpful to mention this in the Yii2 documentation so users who configure their editor for 2-space indentation can quickly identify .editorconfig as the source of the behavior.
This is especially relevant for editors that automatically honor .editorconfig, such as Zed.
Source: yiisoft/yii2