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 Overflow
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
JS Beautify - Visual Studio Marketplace
Extension for Visual Studio Code - A little wrapper around "js-beautify" for conveniently beautifying CSS/HTML/JS files.
๐ŸŒ
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 - We can see the function is on one line: Search for and select Beautify: Click Install: Now, select CTRL + SHIFT + P or the View menu to bring up the Command Palette: Search for Beautify and you will see: Beautify โ€ฆ
๐ŸŒ
GitHub
github.com โ€บ HookyQR โ€บ VSCodeBeautify
GitHub - HookyQR/VSCodeBeautify: Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code ยท GitHub
You can control which file types, extensions, or specific file names should be beautified with the beautify.language setting. { "beautify.language": { "js": { "type": ["javascript", "json"], "filename": [".jshintrc", ".jsbeautifyrc"] // "ext": ["js", "json"] // ^^ to set extensions to be beautified using the javascript beautifier }, "css": ["css", "scss"], "html": ["htm", "html"] // ^^ providing just an array sets the VS Code file type } }
Author ย  HookyQR
Find elsewhere
๐ŸŒ
W3Schools
w3schools.io โ€บ editor โ€บ vscode-format-code
How to format or beautify code in Visual Studio Code tutorials - w3schools
... These documents format the entire file. ... Go to File > Preferences >settings window opened, Select Workspaces. ... { "beautify.onSave": true, "editor.formatOnSave": true, "beautify.JSfiles": [ "js", "json", "jsbeautifyrc", "jshintrc", "ts" ] }
๐ŸŒ
GitHub
github.com โ€บ Unibeautify โ€บ vscode
GitHub - Unibeautify/vscode: Unibeautify for VSCode
For example, the .vscode/settings.json below adds the .myphp file extension to the php language identifier: ... By default all languages supported by Unibeautify will be enabled. You can disable a specific language by setting the language options to false as shown below. Important: You must restart/reload VSCode after enabling/disabling a language. ... --- CSS: false # Disable CSS! JavaScript: # Enable TypeScript beautifiers: ["Prettier"] # Enable beautifiers indent_style: "space" indent_size: 2
Starred by 120 users
Forked by 14 users
Languages ย  TypeScript 92.8% | JavaScript 4.1% | PHP 2.4%
๐ŸŒ
Beautifier
beautifier.io
Online JavaScript beautifier
End script and style with newline? Support e4x/jsx syntax Use comma-first list style? Detect packers and obfuscators? (unsafe) Preserve inline braces/code blocks? Keep array indentation? Break lines on chained methods? Space before conditional: "if(x)" / "if (x)" Unescape printable chars encoded ...
๐ŸŒ
GitHub
github.com โ€บ Quentium-Forks โ€บ vscode-beautify
GitHub - Quentium-Forks/vscode-beautify: Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code ยท GitHub
You can control which file types, extensions, or specific file names should be beautified with the beautify.language setting. { "beautify.language": { "js": { "type": ["javascript", "json"], "filename": [".jshintrc", ".jsbeautifyrc"] // "ext": ["js", "json"] // ^^ to set extensions to be beautified using the javascript beautifier }, "css": ["css", "scss"], "html": ["htm", "html"] // ^^ providing just an array sets the VS Code file type } }
Author ย  Quentium-Forks
๐ŸŒ
GitHub
github.com โ€บ francismeynard โ€บ vs-code-js-beautify-extension
GitHub - francismeynard/vs-code-js-beautify-extension: This is a code formatter settings almost similar to Eclipse java code formatter using js-beautify
This is a code formatter settings almost similar to Eclipse java code formatter using js-beautify - francismeynard/vs-code-js-beautify-extension
Author ย  francismeynard
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.

๐ŸŒ
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 ย  February 19, 2023
๐ŸŒ
YouTube
youtube.com โ€บ watch
- YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
๐ŸŒ
Chocolatey
community.chocolatey.org โ€บ packages โ€บ vscode-beautify
Chocolatey Software | Beautify VSCode Extension 1.5.0
This extension enables running js-beautify in VS Code, AND honouring any .jsbeautifyrc file in the open file's path tree to load your code styling. Run with F1 Beautify (to beautify a selection) or F1 Beautify file. This package requires Visual Studio Code 1.22.0 or newer. You can install either the vscode or vscode-insiders package.
๐ŸŒ
GitHub
github.com โ€บ Lonefy โ€บ vscode-JS-CSS-HTML-formatter
GitHub - Lonefy/vscode-JS-CSS-HTML-formatter: JS,CSS,HTML formatter for vscode
###To format Javascript,CSS and HTML after vscode v0.10.10 ... Edit the file as your needs. This extension uses js-beautify internally, so you can edit the parameters which js-beautify can use.
Starred by 50 users
Forked by 23 users
Languages ย  TypeScript
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
JS-CSS-HTML Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Format ,prettify and beautify JS, CSS, HTML code by using shortcuts, context menu or CLI