Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make prettier the default formatter in vs code?

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?

like image 519
Márcio Valim Avatar asked Sep 18 '20 11:09

Márcio Valim


5 Answers

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
like image 142
Márcio Valim Avatar answered Oct 22 '22 06:10

Márcio Valim


  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"

like image 45
laurabeth Avatar answered Oct 22 '22 06:10

laurabeth


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.

like image 9
Owen Valentinus Avatar answered Oct 22 '22 07:10

Owen Valentinus


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)
    
like image 7
Stewart Avatar answered Oct 22 '22 07:10

Stewart


  • Update the vs code if necessary.
  • Make sure that you have prettier extension and enabled it.
  • Go to setting by clicking ctrl with comma(,) that opens search setting bar.
  • There search for default editor
  • Select default formatter and choose Prettier - Code formatter

default formatter - Prettier

  • Search for Format on Save and tick the check box

format on save checked

  • This should work, else please let me know.
like image 6
Mahantesh. N. Hadimani. Avatar answered Oct 22 '22 07:10

Mahantesh. N. Hadimani.