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?

9 comments
Comment actions Permalink

There is a setting to control this behavior:

0
Comment actions Permalink

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
Comment actions Permalink

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

0
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

There is no way to disable indentation on Enter: https://youtrack.jetbrains.com/issue/IDEA-147910.

0
Comment actions Permalink

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

Settings > Editor > General > Smart Keys > Enter

2
Comment actions Permalink

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

0

Please sign in to leave a comment.