IntelliJ "keep indents on empty lines" not working
Asked Answered
F

3

7

In Android Studio, i would like to setup the code editor, so i could move cursor with keyboard arrows, or click with a mouse somewhere on a blank line, and the cursor will be placed right bellow the start of a previous line of code.

enter image description here

as i understand, the option keep indents on empty lines should activate this kind of behavior, but unfortunately after setting it up, i still cannot achieve what i wont. if cursor goes to empty line, it is always at the beginning of the line. tried to restart Android Studio, wasn't helpful.

Googled a lot didn't find any info.

If someone knows how to get that behavior, help will be very appreciated.

Fleck answered 14/11, 2015 at 18:39 Comment(1)
This doesn't work in Android Studio BumbleBee. I can't get rid of the stupid indents. Ugly. I can't believe they can't fix this. I have to manually erase all the unnecessary indents. before committing.Crest
L
9

There's an issue in Intellij-Idea very similar to this one that might apply here.

https://youtrack.jetbrains.com/issue/IDEA-144196

The workaround I found was to set the 'Strip trailing spaces on save' option in Settings > Editor > General to 'None'. This works in addition to enabling options in your code style settings that keep the indent on empty lines. From what I can surmise, it seems like the logic that applies the rule to indent conflicts or has some sort of order of operations rule issue with the option to strip trailing spaces.

It's not a perfect workaround... by doing this, you get to keep your tabs on empty lines, but it comes at the cost of also retaining any empty spaces at the end of lines.

I'm not sure if they've fixed this for the Idea 15 release, but if the status of the issue is any indicator, I'm betting not. There may be better workarounds than this one. It's just the one that I tried that yielded acceptable results.

Lennyleno answered 15/11, 2015 at 5:29 Comment(4)
thanks for your answer, unfortunately setting 'Strip trailing spaces on save' to 'None' in addition to enabled 'keep the indent on empty lines' did not solve this problem.Fleck
ok, it is working, only on new code i am writing :) thank you again!Fleck
The CTRL+ALT+L key combo in Idea will apply your formatting rules to the entire file. If Android Studio has a different default configuration, you'll find it in your Keymap settings. I also use a plugin for Idea called 'SaveActions', which applies the formatter automatically when you save your file. If this plugin also is available for Android Studio, it may be an added convenience for you.Lennyleno
now it is working on old files too. it was COMMAND+OPTION+L on a mac and it is "reformat code" action. thanks a lot, now its working exactly as i need))Fleck
C
0

In my case, besides the option keep indent on empty lines, I have to mark this options and now it is working.

enter image description here

Chickabiddy answered 14/1, 2017 at 10:48 Comment(0)
B
0

enter image description here

Edit- > general -> Uncheck Remove trailing spaces on modified line

Bargeman answered 23/12, 2022 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.