How to do auto indentation / code auto formatting in Visual Studio Code?
- On Windows Shift + Alt + F
- On Mac Shift + Option + F
Check out more here: How do you format code in Visual Studio Code (VSCode)? - Stack Overflow
Also: Basic Editing in Visual Studio Code
Xml formatting is not available by default. You can install the extension XML Tools to fix this.
For formatting / auto indenting Apex check Prettier Code Formatter | Salesforce for VSCode
If you get the error "Cannot find module 'prettier'", while trying to auto indent apex after installing Prettier, make sure to install the prettier package by opening your terminal in your project's root directory and running the following command: npm install --save-dev prettier.
If you need to update node to the latest version: How to Update Node.js to the Latest Version (2022) (hostingadvice.com)
By default prettier plugin apex uses 2 spaces as instead of the normal 4 spaces tab. To change that set the tabWidth and useTabs in the config. Check out Enable code formatting for apex in vs code (forcetrails.com) point number 6.
To change the default document formatter: How do you change the formatting options in Visual Studio Code? - Stack Overflow