Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off Eclipse formatter for selected code area? [duplicate]

People also ask

How do I turn off code formatting in Eclipse?

To change these settings, use Window -> Preferences -> Java -> Code Style -> Formatter. On the last tab of the formatter, you can define on/off tags which allow to you to prevent reformatting of some code.

What is @formatter off?

The @formatter: off adds a reference from the code to the editor.

How do I turn off auto format VSCode?

Enable/Disable Format On SaveOpen up VSCode Command Palette by pressing Ctrl + Shift + P. Search and select Open Settings (UI). Just start typing and it will auto-fill. Once there's a match, you can hit enter immediately, or manually click on the right option.


To prevent specific portions of Java code from being formatted, go to "Window > Preferences > Java > Code Style > Formatter". Click the "Edit..." button, go to the "Off/On Tags" tab and enable the tags. Afterwards, you can simply embed those tags in Java code to disable the formatting in-between them. If you don't change the default tags, something like this will do :

//@formatter:off
this.
    portion.of(code
); // will not be touched by the formatter
//@formatter:on
but this will be
       reformatted.

IIRC, this option only exists since Eclipse 3.6.

As for css code, if you have installed Eclipse WTP, go to "Window > Preferences > Web > CSS Files > Editor" and you will find some basic formatting options there.


You cannot configure the formatting at class level, but you can configure at the project level. To do the configuration follow this path in eclipse

window->preferences-> java -> code style -> formatter

now select the configure project specific settings and do your changes.