How to remove unnecessary blank line on code formatting in IntelliJ?

前端 未结 5 998
情深已故
情深已故 2020-12-12 18:56

Is it possible to remove empty/blank lines using code formatting in Intellij IDEA?

5条回答
  •  感动是毒
    2020-12-12 19:38

    I use regular expression to remove extra blank line from code. Here are the instructions

    • Open Find and Replace dialog. Use shortcut CTRL+SHIFT+R.
    • In the search box type ^(?:[\t ]*(?:\r?\n|\r)){2,}. This will search for two ore more blank lines.
    • In a replace box type \n. This will replace with one blank line.

    • Open Reformat Code dialog and click Run. Use shortcut CTRL+ALT+L.

    This works on all JetBrains IDEs. Use the screenshot as referece.

提交回复
热议问题