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.

🌐
W3Schools
w3schools.io › editor › vscode-format-code
How to format or beautify code in Visual Studio Code tutorials - w3schools
Step by Step guide to auto-format code on saving manually or automatically in Visual Studio code VSCode shortcut commands and workspace settings tutorials. Format a code is a beautify source code on code editor using automatically on save or manually with shortcut command.
Discussions

How do i format or beautify code in Visual Studio code?
I have just started using Visual Studio code, but i am not able to format code in it, I have tried ctrl k+ Ctrl d but it doesn't work, any helpful link for it?... More on qawithexperts.com
🌐 qawithexperts.com
3
2
August 17, 2022
How to format code completely?
Resharper, or use jetbrains Rider instead of Visual Studio. More on reddit.com
🌐 r/VisualStudio
11
6
October 5, 2021
How to automatic format code in Visual Studio
I remember I had an automatic code formating right after I pressed ctrl+s. Now I don't have that. All I have is "Code Formatter" that makes a lot of commets which I don't need and when I remove those comments with "Clear… More on learn.microsoft.com
🌐 learn.microsoft.com
6
4
Visual studio code CSS indentation and formatting - Stack Overflow
I'd like to know if there is any way to activate auto indent a CSS file in visual studio code with the shortcut ALT+SHIFT+F? It's working fine with JavaScript but strangely not with CSS. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Beautify - Visual Studio Marketplace
May 2, 2019 - Extension for Visual Studio Code - Beautify code in place for VS Code
🌐
Carl de Souza
carldesouza.com › home › posts › how to beautify a javascript file in visual studio code
How to Beautify a JavaScript File in Visual Studio Code - Carl de Souza
September 11, 2020 - First, let’s create a really simple JavaScript file. We can see the function is on one line: Search for and select Beautify: Click Install: Now, select CTRL + SHIFT + P or the ...
🌐
Sentry
sentry.io › sentry answers › vs code › format code in visual studio code
Format code in Visual Studio Code | Sentry
To format the contents of the current file, we can either use the shortcut Ctrl+Shift+I (Command+Shift+I on macOS) or bring up the command palette with Ctrl+Shift+P (Command+Shift+P on macOS) and then search for and execute “Format Document”.
Find elsewhere
🌐
GitHub
gist.github.com › muta1 › a53311cfbdf6a02efcf17b760d5e4406
vscode: beautify with shortcut ctrl+s - file: keybindings.json · GitHub
November 3, 2021 - vscode: beautify with shortcut ctrl+s - file: keybindings.json · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
YouTube
youtube.com › watch
How To Beautify Visual Studio Code Tutorial - YouTube
How To Beautify Visual Studio Code TutorialToday we talk about beautify in vs code,visual studio code,beautify,vscode tutorial
Published   November 11, 2022
🌐
GitHub
github.com › HookyQR › VSCodeBeautify
GitHub - HookyQR/VSCodeBeautify: Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code · GitHub
Use the following to embed a beautify shortcut in keybindings.json.
Starred by 607 users
Forked by 184 users
Languages   JavaScript
🌐
LinkedIn
linkedin.com › pulse › visual-studio-code-auto-format-shortcut-key-billour-ou
Visual studio code auto format code with shortcut key
February 14, 2023 - Published May 18, 2022 · + Follow · Visual studio code's shortcut key for each OS. On Windows : Shift + Alt + F · On MAC OS: command + k + f · On Ubuntu : Ctrl + Shift + I · VS Code has great support for source code formatting.
🌐
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
🌐
Microsoft Learn
learn.microsoft.com › en-us › visualstudio › ide › code-styles-and-code-cleanup
Code Style Options and Code Cleanup - Visual Studio (Windows) | Microsoft Learn
In the Tools > Options pane, expand the All Settings > Languages > C/C++ > Code Style > Formatting > General section. You can also use the Ctrl + Q keyboard shortcut and search for Formatting.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
CodeBeautifier - Visual Studio Marketplace
March 22, 2018 - Extension for Visual Studio - Code beautifier front end Add-in for Visual Studio evironment. Allows to use of any external code format application.
🌐
Reddit
reddit.com › r/visualstudio › how to format code completely?
r/VisualStudio on Reddit: How to format code completely?
October 5, 2021 -

Hi! I was wondering if there's a way to format the code automatically. VS has it's own formatter but it doesn't add semicolon automatically and it doesn't format empty space well enough. In VS code for example, when I format it formats everything well.

Couldn't find an extension for VS like prettier or beautify.

How can I automate this?

🌐
GitHub
github.com › vsce-toolroom › vscode-beautify
GitHub - vsce-toolroom/vscode-beautify: Beautify code in place for VS Code. · GitHub
Use the following to embed a beautify shortcut in keybindings.json.
Starred by 14 users
Forked by 2 users
Languages   JavaScript