How to config intellij-idea not format some part of the code?

后端 未结 4 1278
借酒劲吻你
借酒劲吻你 2021-02-05 00:54

In a html file, there is some code used custom template-language:



        
相关标签:
4条回答
  • 2021-02-05 01:31

    It's worth noting that the formatter control does not appear to work in javadoc comments. It needs to be either in a regular C or C++-style comment. So // @formatter:off works /* @formatter:off */ also works, but /** @formatter:off */ does not.

    0 讨论(0)
  • 2021-02-05 01:32

    In my version EAP 13.1, you must enable the following option in settings,

    Preferences -> Code Style -> General -> Formatter Control -> Enable formatter markers in comments

    before you can use these comments,

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

    or these (depending on language):

    <!--@formatter:off-->
    
    <!--@formatter:on-->
    

    Screenshot:

    Screenshot highlighting the checkbox for Enable formatter markers in comments under Preferences

    0 讨论(0)
  • 2021-02-05 01:40

    This feature has been implemented and you can now disable formatting for the regions of code using the special comments.

    After enabling this feature in the settings, add //@formatter:off at the start of your region, and //@formatter:on at the end of it.

    These are the default markers, and they are configurable.

    You can find more details and examples in the documentation:

    • Skipping a region when reformatting source code
    • Example of using formatting markers

    Original answer from 2012:

    It's not possible yet, please vote for this feature request:

    • IDEA-56995 Disable code formatting per region using comments
    0 讨论(0)
  • 2021-02-05 01:42

    Since EAP 13 you can trigger the formatter with the following comments:

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

    To enable it in "surround with", you can define a Live Template in the section "surround" with:

    // @formatter:off
    $SELECTION$
    // @formatter:off
    

    You can find these settings in Settings -> Code Style -> General and set your own trigger words.

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