简体   繁体   English

键入右括号时禁用Intellij IDEA代码重新格式化

[英]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. 一旦输入右括号,Intellij IDEA似乎想重新格式化括号内的代码块。 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. 例如,如果我有一个代码块,我现在想要在try / catch块中包装,一旦我输入try块的右括号,整个try块就会自动重新格式化。 I have searched in settings but was not able to find anything that would turn this off. 我在设置中进行了搜索,但未能找到任何可以解决此问题的内容。 Any ideas? 有任何想法吗?

Yes. 是。

File --> Settings --> Editor --> General --> Smart Keys 文件 - >设置 - >编辑器 - >常规 - >智能钥匙

Then uncheck the option "Reformat block on typing '}'" 然后取消选中“在键入时重新格式化'}'选项”

Apply --> OK 申请 - >好的

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 然后你必须把你的代码放在comments :: // @formatter:off// @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. 如果清除该复选框,则将忽略格式标记,并且将重新格式化带有标记的行注释之间的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM