Disable reformatting code when saving files

前端 未结 4 1529

I made a small change to an old java file in IntelliJ and when I save the file the IDE automatically reformats all the code. Normally this would be preferable, however it seems

相关标签:
4条回答
  • 2021-02-02 12:43

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

    0 讨论(0)
  • 2021-02-02 12:51

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

    0 讨论(0)
  • 2021-02-02 13:02

    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...

    0 讨论(0)
  • 2021-02-02 13:07

    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"

    0 讨论(0)
提交回复
热议问题