How to remove unnecessary blank line on code formatting in IntelliJ?
-
15-06-2021 - |
Frage
Is it possible to remove empty/blank lines using code formatting in Intellij IDEA?
Lösung
Yes. It is possible to configure the number of blank lines in the settings menu (CTRL+ATL+S): File -> Settings -> Editor -> Code Style -> Java(or Scala or whatever your language is) -> Blank Lines
Andere Tipps
You can find and replace with regex option also ^(?:[\t ]*(?:\r?\n|\r))+
. It searches all empty lines in file. You need to just replace it with empty
Just in case it helps someone using newer versions of Intellij, in Intellij IDEA 2016.2.4 it is File -> Other Settings -> Default Settings -> Editor -> Code Style -> Java(or Scala or whatever your language is) -> Blank Lines
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.