Home > Software design >  How to make automatic formatting of a java file seperate methods with 2 lines on VSC
How to make automatic formatting of a java file seperate methods with 2 lines on VSC

Time:11-20

I want to make VSC add 2 lines automatically between methods as part of the 'Format Document' keyboard shortcut (Shift alt f).

I shifted from Eclipse to VSC a couple of weeks ago and in Eclipse I had the option to freely customize pretty much any part of the document's auto-formatting. I've been searching for a way to do this on VSC but I couldn't find what I'm looking for. Not sure if it matters but I'm writing my code in java.

Basically what I want to happen is:

public class Testing {

   public void func1() {
      //Some code
   }

   public void func2(){
      //Some code
   }

   public void func3(){
      //Some code
   }

Shift alt f ==>

public class Testing {

   public void func1() {
      //Some code
   }


   public void func2(){
      //Some code
   }


   public void func3(){
      //Some code
   }

CodePudding user response:

Open Command Palette and choose Java: Open Java Formatter Settings with Preview, then there'll be an notification popping up, click Generate a default profile, then java-formatter.xml will be displayed in the folder .vscode.

Open java-formatter.xml and set :

<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="2"/>

enter image description here

  • Related