Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable code formatting for some part of the code using comments?

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?

like image 507
Greg Mattes Avatar asked Jul 30 '10 20:07

Greg Mattes


People also ask

How do I stop formatting in Intellij?

To disable : Settings > Editor > File Types. Select the file type you want to have never formatted.

How do I fix code formatting?

Press Ctrl+Alt+L/Cmd+Alt+L to automatically fix code formatting in a file.

What is the code formatting?

Code formatting provides you with many opportunities to subtly communicate your intent to a reader. Far from being a backwater best left to draconian "style guides", code formatting is often your reader's first encounter with your system. It deserves attention and care.


1 Answers

Since version 13 it's possible to wrap the code with

// @formatter:off ... // @formatter:on  

IntelliJ IDEA v.2018+:

File > Settings > Editor > Code Style

IntelliJ IDEA v.2016+:

Preferences > Editor > Code Style

IntelliJ IDEA v.14+:

Preferences > Editor > Code Style > Formatter Control

You can change the formatter control markers, as long as they're in comments.


Ensure formatter markers in comments are enabled, as shown in the following figure:

Formatter Control Preference

like image 79
Carlos Fonseca Avatar answered Sep 18 '22 18:09

Carlos Fonseca