Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 573
Eugene Avatar asked Jun 20 '12 11:06

Eugene


People also ask

How do I fix code format in IntelliJ?

Go to Settings/Preferences | Editor | Code Style, select your programming language, and open the Wrapping and Braces tab. In the Keep when reformatting section, select the formatting rules which you want to ignore and deselect those which should be applied. Reformat your code ( Ctrl+Alt+L ).

How do you remove the last empty line in Java?

replaceAll() may be replacing a line at the end and leaving the line blank. Use str2. trim() or move str2 = str2. replaceAll("\\s","") after the second replaceAll() .


2 Answers

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

Blank lines configuration

like image 129
Vic Avatar answered Oct 09 '22 21:10

Vic


  • File >> Setting >> Editor >> Code style java >>Blank lines tab

  • You should change to 0 in code label(as picture), It would remove all unnecessary blank line when press format shortcut: ctrl + alt + L

enter image description here

like image 25
huu duy Avatar answered Oct 09 '22 22:10

huu duy