Beautify on save in VS code?

41,920

Solution 1

For Windows click on 'File' -> Preferences -> Settings. Then search for editor.formatOnSave, and put "true" instead of "false"

For Mac click on 'Code' (top left of screen, to the left of 'File', 'Edit', and 'View') -> Preferences -> Settings -> enter the term 'editor.formatOnSave' in the search settings box at the top of the page. Click on the tick to mark it as true.

enter image description here

Solution 2

Go to file--> preferences --> settings

In search type formatter and in default formatter select : prettier code formatter as shown in below screenshot.

enter image description here

Solution 3

I visited this question because my beautify was not working in VS code And Adding the above mentioned setting fixed my issue but if you want your beautify to solve linting issue as well then you gonna have to added the below setting along with the above like this : (Hope this helps anyone)

{
  "editor.formatOnSave": true,
  "tslint.autoFixOnSave": true
  }
Share:
41,920
UC3D
Author by

UC3D

Updated on January 25, 2022

Comments

  • UC3D
    UC3D over 2 years

    I just installed a beautify extension for vs code

    I want to have my code beautified whenever I save a file, but can't figure out how to configure it that way.

    It says

    Beautify on save will be enabled when "editor.formatOnSave" is true.

    But i have no idea where to put it exactly as I cannot find the default option in any of the files.

    I'm trying to switch to VS code and figure things out.

  • UC3D
    UC3D about 6 years
    i.imgur.com/CcscL2H.jpg Am i doing this right? It doesn't seem to work even after reloading vscode
  • UC3D
    UC3D about 6 years
    Not sure if it does anything. It doesn't beautify my code when i save a file like i want it to.
  • Dave Anders
    Dave Anders about 6 years
    I answered your initial question where to find the setting, so would appreciate +1 :), if you now have another question of why certain plugin doesn't work, I will need more details on that one. Screenshot or copy of the example 'ugly' code, and all steps how you enabled the plugin.
  • Rich
    Rich over 5 years
    It worked for me. Just open an html file and move an element out of place then save the file. The element gets moved back to where it should be.
  • Devin McQueeney
    Devin McQueeney over 2 years
    this does nothing for me