Autoindentation of a new line in Eclipse - how to disable?
Asked Answered
R

1

10

This seems to be a FAQ question, because I know what the corrent answer should be for setting up indentation for Java code in Eclipse (Windows -> Preferences -> Java -> Code Style -> Formatter), but I can't find exactly an option which leads to the following behaviour, which I want to disable.

The problem: every time I press Enter after some text on a line, editor moves text cursor not under the beginning of the previous line, but adds one level of indentation. How can this be disabled in Indigo? I need that every new line is started from a position from which the source line above starts. I tried a lot of controls in the formatter preferences - nothing helped so far. Perhaps I've missed something.

Rapp answered 12/5, 2012 at 19:24 Comment(0)
R
15

I found this: Preferences -> Java -> Editor -> Typing, the checkbox Enter key adjusts the indentation on the new line. (This tab provides editor with extra intelligence apart from formatter and works on the fly. It may be helpful to tweak some of these options depending from personal coding practicies.)

Unfortunately, when this checkbox is off, the editor stops to add paired curly braces even if the options Automatically insert at correct position: braces and Automatically close {Braces} are both on. I don't undertand why the indentation option affects braces, and actually disables this very handy mode.

P.S. Smart insert mode is on as well.

Rapp answered 13/5, 2012 at 8:0 Comment(5)
I'm somewhat reluctantly switching to Eclipse and find this extra indent really annoying. It's consistent across recent versions (I'm using Kepler). Strangely, the Format command will remove the extra indent. Another way to "fix" this is to set the Formatter default indentation to 1, but that leaves you with no option for indenting anything more than one level. Do so many Eclipse users really tolerate this behavior?!?!Moorefield
I'm using Luna Service Release 2 (4.4.2) and the Enter key is still indented with that checkbox disabled. I did restart Eclipse, but it still indents. Braces have the issue Stan posted, just as described. They are automatically closed when you add the open brace after the last parenthesis when creating a new method and you press enter.Carolyncarolyne
On Oxygen.1a Release (4.7.1a) with this option disabled enter indentation keeps settings from the line you press it. So if the line is indented and you press enter, next line is also indented. If the line is not indented, next line stays the same - not indented. And yeah, braces are not closed automatically.Salk
I'm also on Indigo and disabling those checkbox only prevents indentation for new lines if the current line (at which you press Enter) is not indented. If it has indentation, then the new line is also indented. It is funny that Formatter shows that empty new lines are NOT indented :) So is there really a way to achieve this finally..?Papandreou
OK, Eclipse team clearly states this is the desired behavior. I've also discovered that when the caret stands at the very beginning of the line, the newline is not indented when you press Enter, so this works for me good enough (just press right to move to the next line and hit Enter to inset a new empty line - of course when this is not the last line :) ).Papandreou

© 2022 - 2024 — McMap. All rights reserved.