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:
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
Try
Ctrl + k + f
By keeping the ctrl key pressed after selecting all content. this should solved your issue. Check this for more details.Right mouse button and select
Format Document
, or use the shortcutShift+Alt+F
to format the code.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.