Mods, we should add a rule that requires people to specify what language they're talking about. OP, unfortunately there is no universal code formatting tool that I'm aware of. Some could be developed to format based on the textmate grammars that exist for all languages, but I don't think it would be very good. Most languages are formatted using extensions (often language servers). Within specific languages, people often debate the best formatter, and how to modify the settings of that tool. What languages do you care about that most? Answer from its_a_gibibyte on reddit.com
🌐
Medium
thiraphat-ps-dev.medium.com › the-best-code-formatters-for-vs-code-11704e787f92
The Best Code Formatters for VS Code | by Thiraphat Phutson | Medium
June 3, 2024 - Prettier is an opinionated code formatter that supports a wide range of languages, including JavaScript, TypeScript, CSS, HTML, and more. It enforces a consistent style by parsing your code and reprinting it with its rules. Supports Multiple Languages: Prettier works with many languages out of the box. Configurable: You can customize Prettier’s settings to match your preferred code style.
🌐
YouTube
youtube.com › the code city
Auto Code Formatting in VSCode | Best Formatter for Visual Studio Code (2023) - YouTube
In this video, I'll show you the best code formatter for vscode. I've been using prettier along with some other code formatter for visual studio code. Pretti...
Published   December 2, 2023
Views   6K
🌐
Visual Studio Code
code.visualstudio.com › docs › python › formatting
Formatting Python in VS Code
November 3, 2021 - Open a Python file in VS Code. Right-click on the editor to display the context menu. Select Format Document With.... Select Configure Default Formatter... from the drop-down menu. Select your preferred formatter extension from the list. Alternatively, you can set it as the default formatter for all Python files by setting "editor.defaultFormatter" in your User settings.json file, under a [python] scope.
Top answer
1 of 16
6008

The code formatting is available in Visual Studio Code through the following shortcuts:

  • On Windows Shift + Alt + F
  • On Mac Shift + Option + F
  • On Linux Ctrl + Shift + I

Alternatively, you can find the shortcut, as well as other shortcuts, through the submenu View / Command Palette, also provided in the editor with Ctrl + Shift + P (or Command + Shift + P on Mac), and then searching for format document.

For unsaved snippets

  1. Open command palette (Win: F1 or Ctrl + Shift + P)

  2. Find "Change Language Mode"

  3. Select language e.g. json. By now, the syntax should be highlighted.

  4. Format document (e.g. Open Command Palette -> "Format Document")

Unformat

  1. Select text
  2. Command Palette -> Join Lines

'Show the pics'

2 of 16
607

Code Formatting Shortcut:

Visual Studio Code on Windows - Shift + Alt + F

Visual Studio Code on MacOS - Shift + Option + F

Visual Studio Code on Ubuntu - Ctrl + Shift + I

You can also customize this shortcut using a preference setting if needed.

Code Formatting While Saving the File:

Visual Studio Code allows the user to customize the default settings.

If you want to auto format your content while saving, add the below code snippet in the work space settings of Visual Studio Code.

Menu FilePreferencesWorkspace Settings

{
  // Controls if the editor should automatically format the line after typing
  "beautify.onSave": true,

  "editor.formatOnSave": true,

  // You can auto format any files based on the file extensions type.
  "beautify.JSfiles": [
      "js",
      "json",
      "jsbeautifyrc",
      "jshintrc",
      "ts"
  ]
}

Note: now you can auto format TypeScript files. Check my update.

🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-format-code-with-prettier-in-visual-studio-code
Format Code with Prettier in Visual Studio Code: Setup Guide | DigitalOcean
August 1, 2025 - Learn how to format code with Prettier in Visual Studio Code. This guide walks you through installing, configuring, and using Prettier for code formatting.
🌐
Apex Hours
apexhours.com › home › salesforce developer › top 10 vs code extensions
Top 10 VS Code Extensions - Apex Hours
It is an opinionated code formatter that enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. Besides, it supports many languages.
Published   April 18, 2023
Find elsewhere
🌐
GitHub
github.com › mblode › vscode-pretty-formatter
GitHub - mblode/vscode-pretty-formatter: VS Code extension to format your files using Pretty Diff · GitHub
Pretty Formatter VS Code extension provides advanced formatting functionality using Pretty Diff (http://prettydiff.com/) beautify with support for a large variety of programming languages.
Author   mblode
🌐
DEV Community
dev.to › ankushppie › best-vs-code-extensions-boost-your-productivity-part-1-2hlf
15 Best VSCode Extensions to Improve Your Productivity in 2023 (PART-1) - DEV Community
December 19, 2023 - The Better Comments extension will help you to create more human-friendly comments in your code and also provide customization for custom comments and edit the color schema. ... The Prettier - Code formatter is the best tool to format your code ...
🌐
YouTube
youtube.com › watch
Code Formatting Extensions in VSCode - YouTube
This brief tutorial is generally about being productive and forming good habits. Specifically, it is about using the Prettier VSCode extension to help you fo...
Published   January 8, 2020
🌐
Reddit
reddit.com › r/react › what's your approach to auto-formatting your project in vs code?
What's your approach to auto-formatting your project in VS Code? : r/react
March 17, 2023 - If you change it in settings, yes it works but only for you and not anyone else working on the project. That’s why configuration files exist ... I just use the default eslint extension and enabled the option to use it as a formatter, no more linting problems for me!
🌐
Reddit
reddit.com › r/vscode › best auto formatter extension?
r/vscode on Reddit: Best Auto Formatter Extension?
November 19, 2021 -

So I keep seeing Prettier come up when I look for an auto-formatter but I'm a little worried as it says that it's opinionated.

My workplace has very specific coding standards and I'd prefer one that is configurable as possible.

Also preferably with the ability to share those settings with other members of my team.

🌐
WeAreDevelopers
wearedevelopers.com › en › magazine › 201 › vs-code-extensions
19 Great VS Code Extensions
Markdown Preview GitHub Styling is an extension that enables GitHub themes for markdown files inside VS Code. With this extension, you can preview your markdown files in the same way as they will appear in GitHub. This extension has been installed more than 950 thousand times to date in VS Code. Prettier is an opinionated code formatter that helps you establish a consistent pattern in your code.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
VS Code Pretty Formatter
Extension for Visual Studio Code - VS Code extension to format your code using Pretty Diff
🌐
Rapidfreeformatter
rapidfreeformatter.com › home › blogs › best code formatter for vscode javascript: top tools for speed, style & consistency
Best Code Formatter for VSCode JavaScript: Top Tools for Speed, Style & Consistency - RapidFreeFormatter.com: Free Essential Tools
November 3, 2025 - With tools like Prettier, ESLint, StandardJS, Beautify, Rome, and Biome, every developer can find a workflow that fits their style. Prettier is the best choice for most users, while ESLint + Prettier is ideal for advanced projects and teams.
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-linting
Java formatting and linting
November 3, 2021 - Formatting, linting, and code analysis for Java in Visual Studio Code
🌐
Visual Studio Code
code.visualstudio.com › blogs › 2016 › 11 › 15 › formatters-best-practices
Creating a Formatter Extension
November 3, 2021 - The code snippets below show what to do and what not to do when implementing a formatter. The best practice is to use the formatting API and not create a new action, such as "Format Foo File." The full extension example can be found on GitHub.
Top answer
1 of 9
336

Update

Solution A:

Press Ctrl+Shift+P

Then type Format Document With...

At the end of the list click on Configure Default Formatter...

Now you can choose your favorite code beautifier from the list.

If Format Document With... is not available:

Open a file in Visual Studio Code (the extension of the file is not important can be .js, .html, .txt, etc...) then repeat Solution A again.

Solution B:

Windows: go to file -> preferences -> settings
Mac: go to code -> preferences -> settings

in the search bar tpye format, on the left side, click on Text Editor, the very first item on the right side is Editor: Default Formatter from the dropdown you can pick any document formatter which you've installed before.

2 of 9
56

If we are talking Visual Studio Code nowadays you set a default formatter in your settings.json:

  // Defines a default formatter which takes precedence over all other formatter settings. 
  // Must be the identifier of an extension contributing a formatter.
  "editor.defaultFormatter": null,

Point to the identifier of any installed extension, i.e.

"editor.defaultFormatter": "esbenp.prettier-vscode"

You can also do so format-specific:

"[html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[scss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[sass]": {
    "editor.defaultFormatter": "michelemelluso.code-beautifier"
},

Also see here.


You could also assign other keys for different formatters in your keyboard shortcuts (keybindings.json). By default, it reads:

{
  "key": "shift+alt+f",
  "command": "editor.action.formatDocument",
  "when": "editorHasDocumentFormattingProvider && editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly"
}

Lastly, if you decide to use the Prettier plugin and prettier.rc, and you want for example different indentation for html, scss, json...

{
    "semi": true,
    "singleQuote": false,
    "trailingComma": "none",
    "useTabs": false,

    "overrides": [
        {
            "files": "*.component.html",
            "options": {
                "parser": "angular",
                "tabWidth": 4
            }
        },
        {
            "files": "*.scss",
            "options": {
                "parser": "scss",
                "tabWidth": 2
            }
        },
        {
            "files": ["*.json", ".prettierrc"],
            "options": {
                "parser": "json",
                "tabWidth": 4
            }
        }
    ]
}