How to have the formatter wrap code with IntelliJ?

后端 未结 7 1332
梦谈多话
梦谈多话 2020-12-22 17:31

I\'m not able to format my code in IntelliJ.

I can see the margin line (by default at 120 columns) but it seems that the activation from the menu:

7条回答
  •  星月不相逢
    2020-12-22 18:18

    IntelliJ IDEA 14, 15, 2016 & 2017

    Format existing code

    1. Ensure right margin is not exceeded

      File > Settings > Editor > Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded

      File Settings Ensure right margin

    2. Reformat code

      Code > Reformat code...

      Reformat code

      or press Ctrl + Alt + L

      warning If you have something like this:

      thisLineIsVeryLongAndWillBeChanged();   // comment
      

      it will be converted to

      thisLineIsVeryLongAndWillBeChanged();   
      // comment  
      

      instead of

      // comment  
      thisLineIsVeryLongAndWillBeChanged();   
      

      This is why I select pieces of code before reformatting if the code looks like in the previous example.

    Wrap when typing reaches right margin

    • IntelliJ IDEA 14: File > Settings > Editor > Code Style > Wrap when typing reaches right margin

      Wrap when typing

    • IntelliJ IDEA 15, 2016 & 2017: File > Settings > Editor > Code Style > Wrap on typing

      Wrap on typing

提交回复
热议问题