Mensur
Mensur

Reputation: 1308

Disable Intellij IDEA code reformatting when closing brace is typed in

Intellij IDEA seems to like to reformat the code block inside braces once the closing brace is entered. For example, if I have a block of code that I now want to wrap in a try/catch block, once I type in the closing brace of the try block, the entire try block automatically gets reformatted. I have searched in settings but was not able to find anything that would turn this off. Any ideas?

Upvotes: 3

Views: 949

Answers (2)

Ksenia
Ksenia

Reputation: 3731

You must check the option "Enable formatter markers in comments" in

File -> Settings... -> Code Style -> Formatter Control

and then you must put your code between comments: // @formatter:off and // @formatter:on

From the documentation about the option "Enable formatter markers in comments":

If this check box is selected, the fragments of code between the line comments with the formatting markers will not be reformatted but will preserve the original formatting. After you select the check box, the fields below become available and you can specify the character strings to be treated as formatting markers.

If the check box is cleared, the formatting markers will be ignored and the code between the line comments with markers will be reformatted.

Upvotes: -1

Avihoo Mamka
Avihoo Mamka

Reputation: 4786

Yes.

File --> Settings --> Editor --> General --> Smart Keys

Then uncheck the option "Reformat block on typing '}'"

Apply --> OK

Upvotes: 4

Related Questions