Enter creates indented new line

Answered

When hitting `Enter` in IntelliJ I get a new line that's indented with white space. If I hit `Enter` again the previous line still has the leading white space. This causes my file to get a linting error (no-trailing-whitespace) from tslint and I have to go back and delete the white space. Is there a way to allow smart indenting but remove the white space for empty lines?

3
10 comments

There is a setting to control this behavior:

0

Which setting? I tried checking and unchecking Always keep trailing spaces on caret line. Neither worked. I also tried changing Strip trailing spaces on Save: to All but that didn't work either.

0

Strip trailing spaces on Save: All does it: https://i.imgur.com/zJJuFfm.gifv.

0

Okay. It sort of works. I have to hit Ctl-S for it to work even though I have Synchronize files on frame or editor tab activation and Save files on frame activation turned on. I was hoping for something that would do it for me automatically. Ideally, if you hit Enter, hit Enter again and started to type the white space from the previous line would be stripped.

0

It will be stripped anyway on the next automatic or manual file save, like when you alt+tab from the IDE window or close the project.

0

Good afternoon,

Follow up question, please. What if a developer wants to handle the indentation by him/her self? In my case, I wish to start from the beginning of the line each time I press enter inside a class or a namespace. I can then choose to either press tab to get 4 spaces or press enter again.

I would prefer to handle the indentation by myself during typing rather than waiting for the IDE to clean up my mess on save, please.

Thanks in advance!

0
Avatar
Permanently deleted user

I managed to disable this behavior in DataGrip unchecking the option Smart indent under

Settings > Editor > General > Smart Keys > Enter

9
Avatar
Permanently deleted user

Unchecking Smart indent was the answer for me, thank you Lui!

3

thanks for this @..., after 2 years you posted it helped me get rid of this super annoying feature :) 

2

Please sign in to leave a comment.