如何使用注释禁用代码的某些部分的代码格式? [英] How to disable code formatting for some part of the code using comments?
问题描述
我想有选择地禁用 IntelliJ IDEA代码格式化程序代码的一部分就像我在Eclipse中一样。 IntelliJ是否支持此功能,如果是,我该如何使用它?
I'd like to selectively disable the IntelliJ IDEA code formatter for a portion of code just like I can in Eclipse. Does IntelliJ support this feature, and if so, how do I use it?
推荐答案
从版本13开始,可以包装代码with
Since version 13 it's possible to wrap the code with
// @formatter:off
...
// @formatter:on
在版本2016.x中,在首选项>编辑器>代码样式中启用它。 (感谢菲利普)
In versions 2016.x enable it in Preferences > Editor > Code Style. (Thanks Philipe)
在版本2018.x中启用它在文件>设置>编辑器>代码样式(您可以更改格式化程序控件标记,只要它们在注释中)。
In version 2018.x enable it in File > Settings > Editor > Code Style (you can change the formatter control markers, as long as they're in comments).
在版本14中,在首选项>编辑器>代码样式>格式化程序控件
中启用它(感谢 Emerson Farrugia )
这篇关于如何使用注释禁用代码的某些部分的代码格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!