81

I've installed Prettier extension in VS Code, and when I attempt to format a file, VS Code asked me:

Do you want to format with the default formatter or with prettier formatter?

I accidentally chose the default formatter. How can I change this to format with Prettier as default?

Stewart
  • 17,616
  • 8
  • 52
  • 80
Márcio Valim
  • 2,459
  • 3
  • 10
  • 21
  • [Quick Answer](https://stackoverflow.com/a/53419053/14300162) I hope this answer helps you. – Sina Sep 18 '20 at 11:46

5 Answers5

140

Don't know why but setting Default Formatter to ebsenp.prettier didn't work for me. But I found a similar command that worked.

  1. ctrl + shift + p
  2. Format document with
  3. Configure default formatter
  4. Choose prettier
Márcio Valim
  • 2,459
  • 3
  • 10
  • 21
76
  1. Open settings by clicking the cog in the bottom left of the vs code side bar and selecting settings from the menu, or by hitting Ctrl+,

  2. At the top right of the settings pane, hit the open file icon (if you hover, the tooltip will read 'Open Settings (JSON)'

  3. Add the following line to the settings json:

    "editor.defaultFormatter": "esbenp.prettier-vscode"

laurabeth
  • 791
  • 5
  • 3
20

The easiest method I found was this:

  1. Right-Click on a file you wish to format

  2. Select

    Format Document With ...
    

right-click menu


  1. You will be offered a drop-down of different formatters. The final entry will be

    Configure Default Formatter...
    

formatter drop-down


  1. After your selection, if you repeat, you will see the default formatter marked with

    (default)
    
Stewart
  • 17,616
  • 8
  • 52
  • 80
  • 1
    I read some many (I guess too many) answers for choosing a formatter and still didn't understand it properly, but this answer definitely gets it work reliably! – zhouji Feb 21 '23 at 18:50
14
  1. Update the vs code if necessary.
  2. Make sure that you have prettier extension and enabled it.
  3. Go to setting by clicking ctrl with comma(,) that opens search setting bar.
  4. There search for default editor
  5. Select default formatter and choose Prettier - Code formatter

default formatter - Prettier

  1. Search for Format on Save and tick the check box

format on save checked

  1. Note: shift + alt + f also does formatting but without saving document.

enter image description here

  1. This should work, else please let me know.
12

In the command palette(ctrl + shift + p), search for format and then choose Format Document. Then choose Prettier - Code Formatter.

Note: If you do not see a prompt for selecting a default format, you can manually change this in your Settings. Set Editor: Default Formatter to ebsenp.

here is the compelete solution: https://www.digitalocean.com/community/tutorials/how-to-format-code-with-prettier-in-visual-studio-code#:~:text=In%20the%20command%20palette%2C%20search,and%20then%20choose%20Format%20Document.&text=Then%20choose%20Prettier%20%2D%20Code%20Formatter,Editor%3A%20Default%20Formatter%20to%20ebsenp.

Owen Valentinus
  • 611
  • 4
  • 12