How to turn off auto-indenting in Java in Android Studio (2.1.1)? (Windows 7)
Asked Answered
A

2

7

If I have a line with 8 spaces (yes, spaces, not tabs) and some text...

        x=3;

... and my cursor is placed after the semicolon, when I hit Enter it positions the cursor under the x. In other words it indents it 8 positions. If I then hit backspace it positions the cursor after the semicolon! I expect the backspace to take me back 1 space on the new line.

In Editor>Code Style > Java, Tab size = 1, Indent = 0, Continuation indent = 0. N.B. that if I try to set Tab size to 0 it's 1 next time I bring up that dialog, so 0 is apparently not acceptable to Android Studio, even though I see it suggested in several S.O. questions.

In Editor > Code Style I UNchecked Detect and use existing file indents for editing and now if I hit Enter with the cursor after the semicolon it positions the cursor 4 spaces in the from the right, in other words it still indents, just not as much.

N.B, that after making these settings I did a File > Invalidate Caches / Restart.

I don't want any automatic indenting. When I hit Enter I want it to position the cursor at the first position of the new line, and when I hit backspace I want it to go back 1 position, just like an ordinary "dumb" editor. How do I turn off all automatic indenting in Android Studio?

Alcoholometer answered 6/6, 2016 at 15:49 Comment(2)
if you want a dumb editor, why are you not using a dumb editor?Subvention
I don't want a dumb editor - I just want to the enter/backspace/indenting/tab behavior to stop trying to be "smart" (and thus getting it wrong). Eclipse and Visual Studio don't have this problem. Smart editors have many other benefits like language-specific syntax checking, autocomplete, color-coding keywords and data-types, viewing variables in debug, etc, etc.Alcoholometer
B
5

Android studio tries its best, like most IDEs, to help you organize your work and make it successful. It is normal, but of course, there is a way to disable it.

Note: Your project can be really messy when disabling this, if you want to properly indent a block of code, highlight it then press CTRL+ALT+L, this will indent the highlighted for you.

So, to disable it, press CTRL+ALT+S, this will open settings. Now, go to the Editor tab at your left, where you then go to General, then Smart Keys. You should see a "Backspace" part. Over there, there will be a dropdown menu, click that then select the "Disabled" option. (Settings>Editor>General>Smart Keys> )

Bicipital answered 14/6, 2016 at 20:35 Comment(0)
P
2

Is this just the normal, expected behavior of A.S.?

I'd say it's the normal expected behavior of any IDE to indent correctly while you are typing. Your next line is supposed to start at the same position than the previous and if you close a bracket A.S. will automatically unindent it once.

Now on your topic :

To make your backspace key just delete the space you can go to : Settings -> Editor -> General -> Smart Keys -> Backspace -> Unindent and put 'Disabled' instead of 'To proper indent position'

Pasadena answered 8/6, 2016 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.