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'

Answer from npc2b on Stack Overflow
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.

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Prettier - Code formatter - Visual Studio Marketplace
January 21, 2026 - Extension for Visual Studio Code - Code formatter using prettier
Discussions

How to make vs code format my code constantly?
Not enough details. What language are you trying to format? Not all languages are supported by default. What VSCode Extensions are you using? Even if you have the proper VSCode extension, the extension might need to be configured to point to local software to do the linting. More on reddit.com
🌐 r/vscode
15
7
October 8, 2024
What's your approach to auto-formatting your project in VS Code?
Prettier plugin: DO NOT change any of the settings and setup a .prettierrc in your project. Set Prettier as your formatter and format on save. And then thankfully forget about formatting ever again, for you and your team. EDIT: Set your formatter with "Format document with..." > "Configure Default Formatter" More on reddit.com
🌐 r/react
13
2
March 17, 2023
Best code reformatting tool?
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? More on reddit.com
🌐 r/vscode
6
1
February 6, 2024
🌐
Visual Studio Code
code.visualstudio.com › docs › python › formatting
Formatting Python in VS Code
November 3, 2021 - Search the VS Code Marketplace for the formatter extension of your choice.
🌐
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 - Note: If you do not see a prompt for selecting a default formatter, you can manually set Prettier as the default formatter in VS Code. Open your Settings and set Editor: Default Formatter to esbenp.prettier-vscode.
🌐
Visual Studio Code
code.visualstudio.com › docs › csharp › formatting-linting
Formatting and Linting
November 3, 2021 - Formatting and linting C# source code in Visual Studio Code
🌐
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 - Whether you prefer the comprehensive support of Prettier, the linting and formatting capabilities of ESLint, the readability focus of Beautify, or the powerful formatting of clang-format, there is a tool that fits your needs.
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › codebasics
Basic editing
November 3, 2021 - VS Code has default formatters for JavaScript, TypeScript, JSON, HTML, and CSS.
Find elsewhere
🌐
Built In
builtin.com › articles › vscode-c-formatter-settings
VS Code C Formatter Settings Guide | Built In
December 13, 2024 - One of the key features of VS Code is its ability to automatically format your code to make it more readable and consistent. In this article, we’ll examine how to configure C++ code formatting in VS Code using the built-in formatting options.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
VSCode Custom Local Formatters
Extension for Visual Studio Code - Allows users to register custom local formatters for any language.
🌐
Sentry
sentry.io › sentry answers › vs code › format code in visual studio code
Format code in Visual Studio Code | Sentry
Specific options for each formatter can be configured in the editor settings, which is accessible from File -> Preferences -> Settings or by entering “Settings” into the command palette. Formatting options will be available in the Extensions section, including options for built-in formatters.
🌐
Visual Studio Code
code.visualstudio.com › blogs › 2016 › 11 › 15 › formatters-best-practices
Creating a Formatter Extension
November 3, 2021 - // 👎 formatter implemented as separate command vscode.commands.registerCommand('extension.format-foo', () => { const { activeTextEditor } = vscode.window; if (activeTextEditor && activeTextEditor.document.languageId === 'foo-lang') { const { document } = activeTextEditor; const firstLine = document.lineAt(0); if (firstLine.text !== '42') { const edit = new vscode.WorkspaceEdit(); edit.insert(document.uri, firstLine.range.start, '42\n'); return vscode.workspace.applyEdit(edit); } } }); // 👍 formatter implemented using API vscode.languages.registerDocumentFormattingEditProvider('foo-lang', { provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] { const firstLine = document.lineAt(0); if (firstLine.text !== '42') { return [vscode.TextEdit.insert(firstLine.range.start, '42\n')]; } } });
🌐
GitHub
github.com › mblode › vscode-pretty-formatter
GitHub - mblode/vscode-pretty-formatter: VS Code extension to format your files using Pretty Diff · GitHub
VS Code extension to format your files using Pretty Diff - mblode/vscode-pretty-formatter
Starred by 27 users
Forked by 8 users
Languages   TypeScript
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-linting
Java formatting and linting
November 3, 2021 - You can export an Eclipse formatter file and then use it for your project in VS Code.
🌐
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 - I just use the default eslint extension and enabled the option to use it as a formatter, no more linting problems for me!
🌐
Prettier
prettier.io
Prettier · Opinionated Code Formatter · Prettier
prettier-vscode · Built-in support · Got more?Send a PR · See others · Regularly used by: More than 83% of respondents to State of JS 2021. More than 70% of respondents to State of JS 2020. More than 9.9 million dependent repositories on GitHubCheck Them Out ·
🌐
DEV Community
dev.to › twigman08 › help-setting-up-vscode-formatting-1kf2
Help Setting Up VSCode Formatting - DEV Community
April 20, 2021 - I went ahead and installed the prettier extension for VSCode so I could set the default formatters to what you listed to see what happens.
🌐
iorad
iorad.com › player › 2206257 › VS-Code----How-to-change-default-formatter-on-Visual-Studio-Code
VS Code - How to change default formatter on Visual Studio Code
In this tutorial. you will learn how to change default formatter on Visual Studio Code.. The first step is to open Visual Studio Code, and click Settings.. Click Settings.. Click Text Editor..