如何在 Android Studio (2.1.1) 中关闭 Java 中的自动缩进?(Windows 7的)

问题描述:

如果我有一行包含 8 个空格(是的,空格,而不是制表符)和一些文本...

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

        x=3;

... 并且我的光标位于分号之后,当我按下 Enter 键时,它会将光标定位在 x 下方.换句话说,它缩进了 8 个位置.如果我然后按退格键,它会将光标定位在分号之后!我希望退格键能让我在新行中返回 1 个空格.

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

Editor>Code Style > Java中,Tab size = 1,Indent = 0,Continuation indent = 0.注意如果我尝试将 Tab 大小设置为 0,则下次我打开该对话框时为 1,因此 Android Studio 显然不能接受 0,即使我在几个 S.O.问题.

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.

编辑器>代码样式中,我取消选中检测并使用现有文件缩进进行编辑,现在如果我在分号后用光标按 Enter 键,它会将光标定位 4 个空格从右边开始,换句话说,它仍然缩进,只是没有那么多.

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.

我不想要任何自动缩进.当我按 Enter 时,我希望它将光标定位在新行的第一个位置,当我按退格键时,我希望它返回 1 个位置,就像一个普通的愚蠢"编辑器.如何关闭 Android Studio 中的所有自动缩进?

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?

与大多数 IDE 一样,Android Studio 会尽力帮助您组织工作并使其成功.这是正常的,但当然有办法禁用它.

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.

注意:禁用此功能时您的项目可能会非常混乱,如果您想正确缩进代码块,请将其突出显示然后按 CTRL+ALT+L,这将缩进为您突出显示.

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.

因此,要禁用它,请按CTRL+ALT+S,这将打开设置.现在,转到左侧的编辑器"选项卡,然后转到常规"和智能键".您应该会看到退格"部分.在那里,会有一个下拉菜单,点击它,然后选择禁用"选项.(设置>编辑器>常规>智能键>)

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