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
๐ŸŒ
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 โ€ฆ
๐ŸŒ
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.
๐ŸŒ
Beautifier
beautifier.io
Online JavaScript beautifier
Go: ditashi has ported the javascript formatter to golang, Beautify plugin (github) by HookyQR for the Visual Studio Code IDE, ... Netbeans jsbeautify plugin by Drew Hamlett (github). brackets-beautify-extension for Adobe Brackets by Drew Hamlett (github), codecaddy.net, a collection of webdev-related tools, assembled by Darik Hall, editey.com, an interesting and free Google-Drive oriented editor uses this beautifier,
๐ŸŒ
GitHub
github.com โ€บ HookyQR โ€บ VSCodeBeautify
GitHub - HookyQR/VSCodeBeautify: Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code ยท GitHub
Beautify javascript, JSON, CSS, Sass, and HTML in Visual Studio Code.
Starred by 607 users
Forked by 184 users
Languages ย  JavaScript
Find elsewhere
๐ŸŒ
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
๐ŸŒ
GitHub
github.com โ€บ Unibeautify โ€บ vscode
GitHub - Unibeautify/vscode: Unibeautify for VSCode
--- JavaScript: # Enable language 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% | TypeScript 92.8% | JavaScript 4.1% | PHP 2.4%
๐ŸŒ
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
๐ŸŒ
Prettier
prettier.io
Prettier ยท Opinionated Code Formatter ยท Prettier
JavaScriptPrettier ยท prettier-vscode ยท Built-in support ยท Got more?Send a PR ยท See others ยท Regularly used by: More than 83% of respondents to State of JS 2021. More than 70% of respondents to State of JS 2020. More than 9.9 million dependent repositories on GitHubCheck Them Out ยท
๐ŸŒ
W3Schools
w3schools.io โ€บ editor โ€บ vscode-format-code
How to format or beautify code in Visual Studio Code tutorials - w3schools
Step by Step guide to auto-format code on saving manually or automatically in Visual Studio code VSCode shortcut commands and workspace settings tutorials
๐ŸŒ
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
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.