You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
then when I open e.g. the HandlerHelperTest.java file, VS Code shows "Spaces: 8" in the bottom bar and formatting the file changes it to use indentation of 8 spaces instead of 4
The settings file should be fine because when I go back to command line and run mvn formatter:format in the project, the indentation is changed back to 4 spaces.
Why would the "current" tab size differ from the default?
The default tab size should be configured via VS Code setting editor.tabSize. As for the current tab size, you can check VS Code setting editor.detectIndentation, if it's set, VS Code will auto detect the indentation of your current file and show it.
Agree. Currently as for indentation settings, vscode-java will pick VS Code ones rather than the specific settings in profile. That would be not suitable since most users want to specific indentation settings within a project via a profile, we should fix it.
I had the same issue. Every time I was opening a Java file in my project, VSCode would randomly pick 8 spaces indentation instead of 4. My understanding is that the automatic detection of indentation is pretty dumb and doesn't take into account that continuation indentation is usually 2x of normal indentation size.
Like if I have a method with a long list of parameters which I want to place each on a separate line, then those lines will have indentation of 8 spaces.
If the detectIndentation feature "sees" that there are many lines with 8 spaces indentation, more than lines with 4 spaces indentation, then it decides that the default should be 8 spaces, which is obviously wrong. See this related report: microsoft/vscode#193543
But there is another issue!
I now have the following configuration in my settings.json.
Java files get correctly formatted when saved, everything according to my custom formatting rules in the eclipse_code_style.xml. The problem though is that this OnSave formatting doesn't match Live formatting when I'm writing the code.
Take the same above example with method input parameters placed each on a new line. When I hit Enter after the opening parenthesis, live formatter only inserts 4 spaces. Now, if I save the file, another 4 spaces injected to get 8 spaces continuation indentation according to the config.
This discrepancy in formatting is quite annoying, and I don't know what causes it. Must be a bug?
Activity
CsCherrYY commentedon Mar 24, 2023
are you using editorconfig in your project?
Artur- commentedon Mar 24, 2023
No
.editorconfigfile as far as I can seeArtur- commentedon Apr 1, 2023
If I select "Ident Using Spaces", I see this

Why would the "current" tab size differ from the default?
Some files in the project show "Spaces: 8" and other files seem to use the default and show "Spaces: 4"
CsCherrYY commentedon Apr 3, 2023
The default tab size should be configured via VS Code setting
editor.tabSize. As for the current tab size, you can check VS Code settingeditor.detectIndentation, if it's set, VS Code will auto detect the indentation of your current file and show it.Artur- commentedon Apr 3, 2023
Thanks! Now it works as expected when I turned of
editor.detectIndentation.But does it not kind of defeat the purpose of having formatter settings defined, if they are not used by default for incorrectly formatted files?
CsCherrYY commentedon Apr 3, 2023
Agree. Currently as for indentation settings, vscode-java will pick VS Code ones rather than the specific settings in profile. That would be not suitable since most users want to specific indentation settings within a project via a profile, we should fix it.
slowhigh commentedon May 30, 2025
any update?
bigunyak commentedon Feb 13, 2026
I had the same issue. Every time I was opening a Java file in my project, VSCode would randomly pick 8 spaces indentation instead of 4. My understanding is that the automatic detection of indentation is pretty dumb and doesn't take into account that continuation indentation is usually 2x of normal indentation size.
Like if I have a method with a long list of parameters which I want to place each on a separate line, then those lines will have indentation of 8 spaces.
If the
detectIndentationfeature "sees" that there are many lines with 8 spaces indentation, more than lines with 4 spaces indentation, then it decides that the default should be 8 spaces, which is obviously wrong. See this related report: microsoft/vscode#193543But there is another issue!
I now have the following configuration in my settings.json.
Java files get correctly formatted when saved, everything according to my custom formatting rules in the
eclipse_code_style.xml. The problem though is that this OnSave formatting doesn't match Live formatting when I'm writing the code.Take the same above example with method input parameters placed each on a new line. When I hit Enter after the opening parenthesis, live formatter only inserts 4 spaces. Now, if I save the file, another 4 spaces injected to get 8 spaces continuation indentation according to the config.
This discrepancy in formatting is quite annoying, and I don't know what causes it. Must be a bug?