- Published on
Format and Re-Indent Your Code Automatically in VS Code
- Authors
- Name
- Emil Moe
VS Code’s re-indent shortcut quickly formats your entire file, fixing indentation and applying formatting rules based on your settings or formatter.
Platform | Shortcut |
---|---|
Windows/Linux | Shift + Alt + F |
macOS | Shift + Option + F |
What it does
- Re-indents the entire document
- Applies formatting rules (from settings, Prettier, etc.)
Before using it
editor.tabSize
andeditor.insertSpaces
are set correctly- tabSize 2
- insertSpaces true
- Your formatter is installed and configured properly
Format on save
To automatically format your code every time you save, add this to your settings.json
:
{
"editor.formatOnSave": true
}
Then just save to re-indent and format automatically.