IntelliJ does not respect indentation settings of 4 spaces (CTRL+SHIFT+F changes it to 2 spaces)

Answered

I have set the indentation to 4 spaces. The files in Git are indented with 4 spaces. When I press CTRL+SHIFT+F, the whole file changes to 2 spaces indentation. Detect and use existing file indents for editing is turned of. Turning it on did not change anything. 

 

1
8 comments

Hello,

Is EditorConfig support enabled on the File | Settings | Editor | Code Style page? Do you have any custom .editorconfig files in your project?

0

This is the current setting on the code style page

I can see no Editorconfig file in the folder

 

0

Did you try restarting the IDE via File | Invalidate Caches & Restart?

Would it be possible for you to provide a sample file that gets incorrect indentation, and also your code style settings exported into an XML?

0

I just found out, the option "Reformat file" in the "Save Actions" plugin was causing this

 

When turning off the "Reformat file" (whole file) option and instead turning on the "Reformat only changed code ..." option, it formats properly.

However, some redundant whitespace characters are added to blank lines. For example when creating a new class with a method and making a new line after the closing bracket of the method, the cursor is indented automatically 4 characters. When I then hit save, the cursor stays there. I would have expected the whitespace to go away on save. But maybe that's a bug in the "Save actions" plugin?

Note that I DON'T have editorconfig or prettier active.

1

Does it work in the same way if you temporarily disable Save Actions plugin? Try also to move the caret to some other place before saving the file.

0

Turning the save actions plugin off had no effect.

But indeed, when creating a new line below the closing bracket and then moving up the cursor into the line above and then saving (with save actions enabled again) removes the whitespace in the new line

 

0

Thank you for checking. You can try disabling Keep trailing spaces on caret line option:

1

Thank you, that works :)

 

0

Please sign in to leave a comment.