If you want to beautify the code, you can just press
Ctrl+Shift+P and type format code or press Alt+Shift+F
It correctly indents my code so it seems like that is what you are looking for, if not you might want to give an example.
Answer from Dick van den Brink on Stack OverflowVideos
If you want to beautify the code, you can just press
Ctrl+Shift+P and type format code or press Alt+Shift+F
It correctly indents my code so it seems like that is what you are looking for, if not you might want to give an example.
You can use the shortcuts to beautify the code in Visual Studio Code:
- On Windows: Shift + Alt + F
- On Mac: Shift + Option + F
- On Ubuntu: Ctrl + Shift + I
As per the Programming language (PHP, HTML, JavaScript, ASP, JSP, etc.) it will ask you to install a package, after installation you can use above shortcuts.
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 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.