VS Code Formatting Shortcuts: How to Format Your Code Instantly
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.
- * Clean whole files instantly with Shift + Alt + F (Option + Shift + F on macOS).

VS Code Formatting Shortcuts: How to Format Your Code Instantly
To format an entire document in Visual Studio Code, press Shift + Alt + F on Windows/Linux or Option + Shift + F on macOS. This command cleans up indentation, aligns brackets, and fixes inconsistent line breaks across your file based on your active language settings.
What are the Best VS Code Formatting Shortcuts?
The primary formatting shortcut in VS Code is Shift + Alt + F on Windows/Linux or Option + Shift + F on macOS to format an entire document. For targeted edits, highlight code and press Ctrl + K, Ctrl + F (macOS: Cmd + K, Cmd + F) to format only your active selection.
These key combinations handle basic cleanup duties that would otherwise take manual labor to fix. Instead of hunting down rogue spaces or fixing nested indents line by line, hitting the shortcut hands off the heavy lifting to VS Code's internal language server.
Depending on the file type you're working with, the editor applies syntax-specific rules automatically. A JavaScript file formats differently than an HTML file or a JSON document, ensuring your structure stays valid without breaking code execution.
Setting Up Built-in VS Code Formatting

VS Code includes native formatting support for languages like HTML, CSS, JavaScript, and JSON right out of the box. You can configure these built-in rules using settings like tab size, insert spaces, or auto-formatting toggles like 'Format On Save', which automatically cleans up your code every time you save a file.
If you don't want to memorize hotkeys, automating the process makes sense. You can enable automatic cleanup through the settings menu (Ctrl + , or Cmd + , on macOS) by searching for "Format On Save." Checking that box triggers a sweep every time you hit save, keeping your branch clean without extra thought.
You can also turn on "Format On Type," which cleans up code blocks the moment you hit semicolon or brace keys. While some developers find that setting slightly distracting while mid-logic, it works well if you prefer immediate feedback as you write.
Formatting Selected Lines vs. Entire Files
Full-file formatting updates every line in your document, while targeted selection formatting with Ctrl + K, Ctrl + F (macOS: Cmd + K, Cmd + F) cleans up only highlighted code. Using selection formatting helps prevent unnecessary lines from cluttering git diffs when working inside older or shared project codebases.
When you join an ongoing software project, running a full-document format on a legacy file can accidentally rewrite hundreds of lines of stylistic formatting. That leads to messy code reviews where your teammates have to wade through dozens of trivial whitespace changes just to review a three-line bug fix.
By highlighting only the lines you touched and hitting the selection shortcut, you confine your changes strictly to your work. It's a habit that keeps pull requests clean and simplifies team code reviews.
Popular Formatting Extensions: Prettier, ESLint, and Black
Dedicated formatting extensions expand VS Code's abilities across different programming languages and team style guides. Prettier serves as an opinionated web development standard, ESLint combines code formatting with JavaScript bug detection, and Black automatically enforces PEP 8 compliance across Python projects with virtually no manual configuration needed.
While the built-in formatter handles simple tasks, dedicated extensions give teams consistent rules across different operating systems and developer setups. Installing an extension like Prettier ensures every developer working on the repository formats code to the exact same line lengths and quote types.
Once you install these tools from the VS Code Extensions tab (Ctrl + Shift + X), you need to assign them as your default formatter. You can do this globally or on a per-language basis using your global user settings file.
How to Fix Common VS Code Formatting Problems
When formatting shortcuts stop working, the problem usually stems from syntax errors, uninstalled language extensions, or conflicting default formatters. You can quickly fix keybinding conflicts by opening the Command Palette (Ctrl + Shift + P) and selecting 'Format Document With...' to assign your preferred tool for the active file.
If pressing the shortcut does nothing at all, check the bottom status bar for syntax error indicators. Many language formatters refuse to execute if your file contains incomplete functions, missing closing tags, or broken syntax, as running a format could alter the code's intent.
If syntax isn't the issue, two extensions might be fighting over the same file type. Here is a reliable way to resolve conflicts:
- Open the file that won't format properly.
- Press Ctrl + Shift + P (macOS: Cmd + Shift + P) to open the Command Palette.
- Type
Format Document With...and hit Enter. - Select "Configure Default Formatter..." from the dropdown list.
- Choose your preferred tool (like Prettier or built-in HTML features) to lock it in for that language.
Comparing Popular Formatting Tools
Choosing the right formatting tool depends on your target language, project requirements, and team standards. Prettier handles multi-language web projects with almost zero setup, Black automates PEP 8 rules for Python developers, and ESLint gives JavaScript developers full control over code structure and syntax rules combined.
Each tool approaches code maintenance slightly differently. Some tools focus strictly on visual layout, while others analyze how code actually executes.
| Formatter | Primary Target Languages | Main Focus Area | Configuration Style |
|---|---|---|---|
| Prettier | JavaScript, TypeScript, HTML, CSS, JSON | Visual layout and uniform style | Minimal setup, opinionated defaults |
| ESLint | JavaScript, TypeScript | Code quality, bug prevention, formatting | Highly customizable rules |
| Black | Python | Strict PEP 8 pythonic alignment | Uncompromising, zero-config layout |
🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.
For most frontend web workflows, pairing Prettier for layout with ESLint for syntax checks covers all bases. Python developers usually rely on Black alongside Flake8 or Ruff for complete coverage.
Customizing Formatting Keys and Workspace Settings
To remap keybindings in VS Code, open the Keyboard Shortcuts editor using Ctrl + K, Ctrl + S and search for 'Format Document'. You can also lock in formatting rules across team members by committing a .vscode/settings.json file directly into your project's repository.
If muscle memory pulls your fingers toward key combinations from another editor like IntelliJ or Visual Studio, remapping your shortcuts takes only a minute. Open keybindings, click the pencil icon next to "Format Document," and type your preferred keystrokes.
To keep settings identical across your entire engineering team, create a folder named .vscode at the root of your project directory, then add a settings.json file inside it. Add configurations like this to enforce project-wide rules:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
Checking this file into Git ensures anyone working on the codebase instantly inherits the same save behavior and formatting extensions without manual setup.
Frequently Asked Questions
How do I change the VS Code formatting shortcut?
Press Ctrl + K, Ctrl + S (macOS: Cmd + K, Cmd + S) to open Keyboard Shortcuts. Search for "Format Document," double-click the command, press your desired key combination, and hit Enter to save.
Why isn't my code formatting in VS Code?
This usually happens due to broken syntax in your file, missing language extensions, or multiple formatters conflicting. Use Ctrl + Shift + P and select "Format Document With..." to explicitly pick a working default formatter.
Can I format a specific selection of code in VS Code?
Yes, highlight the lines you want to fix and press Ctrl + K, Ctrl + F (macOS: Cmd + K, Cmd + F). This cleans up only your selected text without modifying the rest of the document.
How do I set Prettier as my default formatter in VS Code?
Install the Prettier extension, open VS Code settings, search for "Default Formatter," and choose "Prettier - Code formatter" from the dropdown menu. You can also configure this per-language in settings.json.
What is the difference between code formatting and linting?
Formatting handles visual structure like indentation, quotes, and line length. Linting analyzes code logic to catch potential bugs, unused variables, and security risks. Tools like ESLint can handle both tasks simultaneously.
🛍 See today's best prices on Amazon and grab the option that fits you.