Everyday Toolkit

VS Code Formatting Shortcuts: Quick Keybinds and Setup Guide

Published 2026-07-27

Updated Jul 2026

Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.

Key takeaways
  • Format code instantly with Shift+Alt+F (Windows/Linux) or Shift+Option+F (macOS)
  • Set up Format on Save to automate document cleanup
  • Custom-configure default formatters per programming language
  • Resolve extension conflicts with VS Code explicitly defined settings
VS Code Formatting Shortcuts: Quick Keybinds and Setup Guide
Photo: Lingfeng Mo via Wikimedia Commons

The universal VS Code default formatting shortcut is Shift + Alt + F on Windows and Linux, or Shift + Option + F on macOS. Pressing this combination instantly cleans up indentation, line wraps, and spacing across your active file based on your active formatter rules.

The Core VS Code Formatting Shortcuts

You can format an entire file in VS Code using Shift+Alt+F on Windows/Linux or Shift+Option+F on macOS. If you only want to tidy a specific section, highlight the target lines and press Ctrl+K Ctrl+F (Cmd+K Cmd+F on Mac) to run selection-only formatting without touching the rest of the document.

These default keybindings handle the vast majority of day-to-day code cleanup. Working inside older, legacy codebases makes selection formatting particularly useful. Reformatting a 2,000-line legacy file all at once often creates massive Git diffs that make code reviews painful. By formatting only the lines you changed, pull requests stay clean and easy to read.

If you prefer different key bindings, you can remap them in seconds. Open the Command Palette with Ctrl+Shift+P (or Cmd+Shift+P on macOS), type "Open Keyboard Shortcuts", and search for "Format Document". Double-click the command to register whatever key combination feels natural for your muscle memory.

Setting Up Format on Save and Format on Paste

VS Code Formatting Shortcuts: Quick Keybinds and Setup Guide
Photo: Sunkissedguy via Wikimedia Commons

Automate your code cleaning by opening Settings (Ctrl+, or Cmd+,), searching for "Editor: Format On Save", and checking the box. Adding "editor.formatOnSave": true to your settings.json ensures that every saved file aligns with your defined rules without requiring manual keyboard triggers.

Relying on manual shortcuts means someone eventually forgets to press the keys before opening a pull request. Setting up auto-formatting removes that human error entirely. Beyond formatting on save, VS Code offers two additional automation settings worth considering:

  • Format On Paste (editor.formatOnPaste): Automatically cleans up code snippets you copy from external documentation or stack traces as soon as they hit your editor.
  • Format On Type (editor.formatOnType): Adjusts the current line's formatting after you press key triggers like semicolons or closing braces.

To set these globally or per language, open your user settings.json file. Here is how a typical JSON setup looks for automatic formatting:

{
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "[javascript]": {
    "editor.formatOnSave": true
  }
}

Customizing Formatters and Resolving Conflicts

When multiple extensions claim formatting rights for a single language, VS Code prompts you to choose a default formatter. You can explicitly set this preference in settings.json using language-scoped properties like "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" } to prevent prompt popups and configuration overlaps.

It is common to run into situations where you have both ESLint and Prettier installed for JavaScript, or both Black and Ruff for Python. If VS Code shows a notification stating "Multiple formatters installed", the editor does not know which rule engine to execute when you press the shortcut.

You can fix this globally or set it up per workspace so team members use the exact same settings. To assign a default formatter through the visual settings UI:

  1. Open a file in your chosen language.
  2. Press Shift+Alt+F (or Shift+Option+F).
  3. Select "Configure Default Formatter..." from the dropdown menu at the top.
  4. Pick your preferred tool (e.g., Prettier, C/C++ Clang-Format, or HTML Language Features).

Language-Specific Formatting Features

Language extensions bring their own dedicated rules to VS Code, overriding general editor defaults. Python developers frequently rely on Black or Ruff, Go programmers use gofmt via the official Go extension, and Web developers rely heavily on Prettier or Biome for automatic HTML, CSS, and JS cleanup.

Different ecosystems handle code layout in distinct ways. In Python, PEP 8 enforcement requires strict adherence to indentation and whitespace spacing around operators. In Go, the official toolchain dictates exact code formatting without giving developers room for style arguments. VS Code respects these ecosystem conventions by delegating work to language-specific binaries.

If you want to use distinct tools for different languages, customize your settings.json block like this:

{
  "[python]": {
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.formatOnSave": true
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.formatOnSave": true
  }
}

Choosing the right formatter depends on your tech stack and team philosophy. Unopinionated tools like ESLint prioritize strict error checking and custom style rules, while opinionated formatters like Prettier and Black enforce strict, unconfigurable styles to end team debates over code formatting entirely.

Here is a breakdown of the formatting tools widely used across development teams:

Tool Primary Use Case Configuration Level Standout Feature
Prettier JavaScript, TypeScript, HTML, CSS, JSON Low (Opinionated) Ecosystem standard; supports nearly all front-end web formats.
ESLint JS/TS code quality and style High (Extensible) Catches logical bugs along with style issues; highly custom rules.
Black Python formatting Minimal (Uncompromising) Produces uniform code layout across Python codebases without style debates.
Ruff Python linting and formatting Moderate Written in Rust; executes almost instantly even on massive codebases.
EditorConfig Cross-editor basic formatting Low Maintains consistent indentation across different IDEs using a root file.

🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.

To maintain consistent styles across engineers using different editors (like Neovim or WebStorm alongside VS Code), add an .editorconfig file to the root of your project directory. VS Code reads this file natively with the EditorConfig extension, overriding local editor tab sizes and line endings.

Troubleshooting Common VS Code Formatting Failures

If your shortcut stops working, check the bottom right status bar to verify VS Code correctly identifies the file extension. Next, open the Output tab (Ctrl+Shift+U / Cmd+Shift+U), select your formatter from the dropdown menu, and inspect log errors caused by syntax breaks or bad project config files.

When pressing the formatting shortcut yields no results, developers usually face one of four issues:

  • Syntax Errors in the Source File: Most formatters refuse to parse files containing broken syntax, such as missing brackets or incomplete statements, to avoid corrupting your code.
  • Workspace Trust Restrictions: If you open a folder in "Restricted Mode", VS Code disables third-party extensions—including formatters—for security reasons. Enable workspace trust for your repository path to fix this.
  • Conflicting Local and Global Config Files: A broken .prettierrc or invalid syntax inside a local configuration file can crash the background formatter process quietly. Check the Output window for parsing error traces.
  • Extension Crashes: Language servers occasionally freeze. Restart VS Code or open the Command Palette and run "Developer: Reload Window" to reset all extension host processes.

Key Steps for a Clean Formatting Workflow

A reliable formatting workflow relies on setting explicit default formatters per language, enabling format on save, and sharing configuration files across your development team. This keeps individual repositories predictable, reduces pull request noise, and eliminates manual cleanup habits during active coding sessions.

To establish a clean environment across all your projects, keep these steps in mind:

  • Master the defaults: Memorize Shift+Alt+F (macOS: Shift+Option+F) for immediate whole-file formatting, and Ctrl+K Ctrl+F for highlighting specific blocks.
  • Automate with Format on Save: Turn on editor.formatOnSave in your global settings so you never have to think about manually triggering formatters.
  • Commit config files to Git: Store configuration files (such as .prettierrc, .eslintrc, or .editorconfig) in your repositories so everyone on the team formats code identically.
  • Isolate language formatters explicitly: Set specific editor.defaultFormatter definitions inside your scope blocks to avoid extension ambiguity.

Frequently Asked Questions

How do I change the default VS Code formatting shortcut?

Open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS), type "Open Keyboard Shortcuts", search for "Format Document", double-click the listing, and press your new key combination.

Can I format only modified lines in Git?

Yes. Set "editor.formatOnSaveMode": "modifications" in your settings.json file. VS Code will then format only uncommitted code lines when saving, keeping legacy untouched.

Why is VS Code formatting not working on save?

Ensure "editor.formatOnSave": true is enabled, verify a default formatter is selected for that language, and check that the file has valid syntax without parsing errors.

What is the difference between ESLint and Prettier?

Prettier strictly handles layout formatting like line wraps and spacing. ESLint analyzes code for code quality errors, logic bugs, and syntax style violations alongside formatting.

How do I format a JSON file in VS Code?

Open the JSON file and press Shift+Alt+F (Shift+Option+F on Mac). VS Code includes built-in native formatting support for JSON documents without needing external extensions.

🛍 See today's best prices on Amazon and grab the option that fits you.

Editorial Team Author & reviewer

Hands-on reviewers testing tools, apps and services so you do not have to. Every article here is hands-on tested and human-reviewed before publishing.