Discussions

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
Mac OS Keyboard shortcut for formatting a document not working
Issue Type: Bug Hi Team, Lately i've obeserved that on Mac OS, keyboard shortcut of "Shift+Option+F" to format a document is not working, instead it is adding a tilde ~ symbol in the ... More on github.com
🌐 github.com
8
February 5, 2022
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? ... you can also find these as well as other shortcuts, through the search functionality provided in the editor with Ctrl +Shift+ P (or Command + Shift + P on Mac... More on qawithexperts.com
🌐 qawithexperts.com
3
2
September 22, 2017
Keyboard short-cut for autoformatting code in VS For Mac
Is this a question or a statement? More on reddit.com
🌐 r/csharp
6
1
May 2, 2018
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.

🌐
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”.
🌐
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 - Open Visual Studio Code. Go to the Extensions view by clicking the square icon on the sidebar or pressing Ctrl+Shift+X (or Cmd+Shift+X on Mac). In the search bar, type Prettier - Code formatter.
🌐
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 ...
Find elsewhere
🌐
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 - The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations: On Windows Shift + Alt + F · On macOS Shift + Option + F · On Linux Ctrl + Shift + I · Note It works for all source codes ...
🌐
Visual Studio Code
code.visualstudio.com › shortcuts › keyboard-shortcuts-macos.pdf pdf
General ⇧⌘P, F1 Show Command Palette ⌘P Quick Open, Go to File… ⇧⌘N
General · ⇧⌘P, F1 · Show Command Palette · Quick Open, Go to File… · ⇧⌘N · New window/instance · Close window/instance · User Settings · ⌘K ⌘S · Keyboard Shortcuts
🌐
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.
🌐
LinkedIn
linkedin.com › pulse › visual-studio-code-auto-format-shortcut-key-billour-ou
Visual studio code auto format code with shortcut key
March 6, 2024 - 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.
🌐
GitHub
github.com › microsoft › vscode › issues › 142261
Mac OS Keyboard shortcut for formatting a document not working · Issue #142261 · microsoft/vscode
February 5, 2022 - Hi Team, Lately i've obeserved that on Mac OS, keyboard shortcut of "Shift+Option+F" to format a document is not working, instead it is adding a tilde ~ symbol in the file at the point of current cursor position. If i do --> right click --> format document with ... --> HTML language features. It formats the document. This is happening with all types of files, currently in my project i have HTML. Markdown, CSS, toml and javascript files. Appreciate your help.. Regards, Abhinav · VS Code version: Code 1.64.0 (Universal) (5554b12, 2022-02-03T04:20:17.224Z) OS version: Darwin x64 21.3.0 Restricted Mode: No
Author   abhinavganguly1987
🌐
Visual Studio Code
code.visualstudio.com › docs › editing › codebasics
Basic editing
November 3, 2021 - Learn about the basic editing features of Visual Studio Code. Search, multiple selection, code formatting.
🌐
Visual Studio Code
code.visualstudio.com › docs › getstarted › keybindings
Keyboard shortcuts for Visual Studio Code
November 3, 2021 - Visual Studio Code lets you perform most tasks directly from the keyboard. This article explains how you can modify the default keyboard shortcuts that come with VS Code. ... If you visit this page on a Mac, you will see the keyboard shortcuts for the Mac. If you visit using Windows or Linux, you will see the keys for that platform. If you need the keyboard shortcuts for another platform, hover your mouse over the key you are interested ...
🌐
HowToDoInJava
howtodoinjava.com › home › code editors › code format shortcuts in vscode (visual studio code)
Code Format Shortcuts in VSCode (Visual Studio Code) - HowToDoInJava
October 8, 2024 - 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
🌐
Microsoft Learn
learn.microsoft.com › en-us › visualstudio › mac › editor-behavior
Code formatting - Visual Studio 2022 for Mac | Microsoft Learn
December 13, 2024 - These actions are set under Visual Studio > Preferences > Text Editor > Behavior, and some of the more commonly used functions are described below: Matching closing braces can be added automatically to code when creating new classes, methods, or properties. When this option is selected, typing { will automatically add }. On-the-fly code formatting is triggered by character presses, such as semi-colon or braces, which will emulate the formatting preferences that are set.
🌐
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   October 3, 2021