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 File โ†’ Preferences โ†’ Workspace 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.

๐ŸŒ
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?

๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ vscode โ€บ how to format source code in visual studio code (vscode)
How to format source code in Visual Studio Code (VSCode) - Mkyong.com
November 4, 2021 - formatting vscode, shortcuts, Windows `Shift + Alt + F`, macOS `Shift + Option + F` and Linux `Ctrl + Shift + I`
๐ŸŒ
TecAdmin
tecadmin.net โ€บ how-to-format-source-code-in-visual-studio-code
How to format source code in Visual Studio Code (VSCode) โ€“ TecAdmin
April 26, 2025 - A formatted code is easy to understand for other developers and allows us to find issues within the source code quickly. This article will help you to format source code in Visual Studio Code (VSCode) editor on various operating systems. You can format code using the keyboard shortcuts.
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ code editors โ€บ code format shortcuts in vscode (visual studio code)
Code Format Shortcuts in VSCode (Visual Studio Code) - HowToDoInJava
September 14, 2022 - The followings are the OS-specific keyboard shortcuts that can format the code for all programming languages in VSCode. On Windows -> Shift + Alt + F On macOS -> Shift + Option + F On Linux -> Ctrl + Shift + I
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/csharp โ€บ visual studio - how to edit auto-format shortcut?
r/csharp on Reddit: Visual Studio - How to edit auto-format shortcut?
November 23, 2014 -

I'm looking to change the keyboard shortcut of the free version Visual Studio 2013 so that I do not need to type CTRL+K then CTRL+D as I find it pretty long for a quick format.

I use the Eclipse IDE pretty extensively and enjoy/abuse the ability to so quickly auto-format a class to my settings. I've already handled setting up VS13 to format the way I want, now I just want to change the shortcut key combination to a shorter one such as LCTRL+LSHIFT+D or similar.

๐ŸŒ
YouTube
youtube.com โ€บ shorts โ€บ Xu3Sf1tP3LE
Format Code in VS Code - Shortcut - YouTube
Learn how to use the powerful Shift+Alt+F shortcut in Visual Studio Code to quickly format your code. This easy-to-use shortcut can save you time and effort ...
Published ย  April 26, 2023
๐ŸŒ
Geekflare
geekflare.com โ€บ development โ€บ how to auto-format in vs code to save time and effort
How to Auto-Format in VS Code to Save Time and Effort
January 2, 2025 - You can use the following shortcuts to either format the entire document or specific-highlighted areas of your code; Shift + Alt + F combination formats the entire document. Ctrl + K, Ctrl + F combination formats a section of your code that ...
๐ŸŒ
KindaCode
kindacode.com โ€บ article โ€บ how-to-format-code-in-vs-code-visual-studio-code
How to Format Code in VS Code (Visual Studio Code) - KindaCode
... VS Code provides handy shortcuts that can help you quickly and conveniently format the whole code file that is being focused: ... You can also open the Command Palette (by pressing Command + Shift + P on Mac or Ctrl + Shift + P on Windows), enter the โ€œformatโ€ keyword into the search ...
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ vs code โ€บ format code in visual studio code
Format code in Visual Studio Code | Sentry
How do I make Visual Studio Code (VS Code) automatically format my code โ€“ i.e. normalize indentation, line breaks, and spacing? Code formatting in VS Code can be invoked through keyboard shortcuts or the command palette.
๐ŸŒ
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 - 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.
๐ŸŒ
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 - Instead of manually enforcing style rules or debating formatting choices in code reviews, you can automate the process using a tool like Prettier - a popular, opinionated code formatter. In this article, youโ€™ll learn how to set up and use Prettier in Visual Studio Code (VS Code) to automatically format your code.
๐ŸŒ
DZone
dzone.com โ€บ coding โ€บ tools โ€บ setting custom shortcuts in visual studio code
Setting Custom Shortcuts in Visual Studio Code
July 23, 2016 - In Visual Studio, the shortcut for Code Formatting is Ctrl+k Ctrl+D but in Visual Studio Code, it's Shift+Alt+F. ... Step 2: Now, on the window on the right i.e.
๐ŸŒ
Answer Overflow
answeroverflow.com โ€บ m โ€บ 1289282337158467595
How to formate code in Visual Studio? - C#
September 27, 2024 - I press the button or shortcut to format Document and says it's ready, for me it's a big mess. I would like a linter for everyone who's working in the project.
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ editing โ€บ codebasics
Basic editing
November 3, 2021 - VS Code has great support for source code formatting. The editor has two explicit format actions: Format Document (โ‡งโŒฅF (Windows Shift+Alt+F, Linux Ctrl+Shift+I)) - Format the entire active file.