Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off auto-indenting in Java in Android Studio (2.1.1)? (Windows 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?

like image 717
user316117 Avatar asked Jun 06 '16 15:06

user316117


People also ask

How to set indentation in android studio?

Change your default indenting for Java (not just on the general Code Style page). Go to File > Settings > Editor > Code Style > Java. On the Tabs and Indents tab click "Use tab character".

How do you change the indent in Java?

Indentation settings for Java Code style scheme settings are configured in Settings/Preferences | Editor | Code Style | Java. Use the tab or space character for indentation and code formatting.


1 Answers

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> )

like image 158
Ali Bdeir Avatar answered Sep 27 '22 18:09

Ali Bdeir