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
Open command palette (Win: F1 or Ctrl + Shift + P)
Find "Change Language Mode"
Select language e.g.
json. By now, the syntax should be highlighted.Format document (e.g. Open Command Palette -> "Format Document")
Unformat
- Select text
- Command Palette -> Join Lines
'Show the pics'


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
Open command palette (Win: F1 or Ctrl + Shift + P)
Find "Change Language Mode"
Select language e.g.
json. By now, the syntax should be highlighted.Format document (e.g. Open Command Palette -> "Format Document")
Unformat
- Select text
- Command Palette -> Join Lines
'Show the pics'


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.
Visual Studio with C# key bindings
To answer the specific question, in C# you are likely to be using the C# keyboard mapping scheme, which will use these hotkeys by default:
Ctrl+E, Ctrl+D to format the entire document.
Ctrl+E, Ctrl+F to format the selection.
You can change these in menu Tools โ Options โ Environment โ Keyboard (either by selecting a different "keyboard mapping scheme", or binding individual keys to the commands "Edit.FormatDocument" and "Edit.FormatSelection").
If you have not chosen to use the C# keyboard mapping scheme, then you may find the key shortcuts are different. For example, if you are not using the C# bindings, the keys are likely to be:
Ctrl + K + D (Entire document)
Ctrl + K + F (Selection only)
To find out which key bindings apply in your copy of Visual Studio, look in menu Edit โ Advanced menu - the keys are displayed to the right of the menu items, so it's easy to discover what they are on your system.
Ctrl + K + D (Entire document)
Ctrl + K + F (Selection only)
Videos
I have
Ctrl + K, Ctrl + F
to format the selected text
or
Ctrl+ K, + Ctrl + D for the document :
You may of used Format Document on Save Visual Studio extension.
Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the CTRL+E,D or CTRL+E,F key shortcuts but with this extension the command 'Format Document' is executed on Save.
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?
Every search ends with a page telling how to reformat code in VS Code.
If you are working on PHP you should download the PHP extension format code.
Press F1 and type:
ext install PHP Code Format
Then Shift + Alt + F will work.
You can also select the code you want to format and right click, find the format code menu item and it should have the keyboard command listed next to it.
By default it should be Shift + Alt/Option + F.
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.