Published on

Format and Re-Indent Your Code Automatically in VS Code

Authors
  • avatar
    Name
    Emil Moe
    Twitter

VS Code’s re-indent shortcut quickly formats your entire file, fixing indentation and applying formatting rules based on your settings or formatter.

PlatformShortcut
Windows/LinuxShift + Alt + F
macOSShift + Option + F

What it does

  • Re-indents the entire document
  • Applies formatting rules (from settings, Prettier, etc.)

Before using it

  • editor.tabSize and editor.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.