skip to Main Content

I switched from Eclipse to VS Code for my Java coding but now Ive just spent an entire day trying to get VS Code to format my Java code correctly.

I tried RedHat’s Language Support for Java Extension, but this didnt work.
Next I tried clang, which now formats my code as intended most of the time, however having it format away/remove these pesky extra tabs/whitespace after a copy paste job has been the bane of my day…

A picture says a thousand words:
enter image description here

No matter what clang formatting options I try, I just cannot get rid of these extra unwanted tabs/whitespace…

Please help.

Even if I have to switch to a different formatter solution instead of clang ill happily do that, I just want my java code to format the same way as my C# code… which automagically removes these tabs/whitespace for me by default.

Thanks

2

Answers


  1. Try Ctrl + k + f By keeping the ctrl key pressed after selecting all content. this should solved your issue. Check this for more details.

    Login or Signup to reply.
  2. Right mouse button and select Format Document, or use the shortcut Shift+Alt+F to format the code.

    enter image description here

    You can also use the command Java: Open Java Formatter with Preview to open the java extended formatting settings, where you can customize the formatting effect.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search