Disable reformatting code when saving files

For newer versions (at least WebStorm 2018), Ctrl + S is bound to a save Macro that has a reformat code action followed by save.

You can remove this reformat with Ctrl + Shift + A search for Macro then modify the save one.

Edit | Macros | Edit Macros | save | - on the Action: Reformat...


Settings | Editor | General > Other | Strip trailing spaces on Save -> None.


Updated for IntelliJ Idea 2021+

Settings | Editor | General > On Save | Remove trailing spaces on: <...> -> None.


Today in 2020 IDEA is silently formatting HTML before commit, which might break your web pages appearance. To disable that unselect this checkbox:

enter image description here


You can add these comments to make it temporarily disable formatting on the file, or a specific function:

// @formatter:off

If you want one section to remain, you can also add this:

// @formatter:on 

IntelliJ Documentation Link

If @formatter:off is not working, you can enable it in preferences:

In IntelliJ Preferences, under Code Style, General, Formatter Control there is a checkbox "Enable formatter markers in comments"