如何让 prettier 成为 vs code 中的默认格式化程序?

How to make prettier the default formatter in vs code?

我在 vs code 中安装了 prettier 扩展,当我点击格式化文件时,vs code 问我:“你想使用默认格式化程序还是使用 prettier 格式化程序进行格式化?”。但是我不小心选择了默认格式化程序。我怎样才能将其更改为默认使用更漂亮的格式?

在命令面板(ctrl + shift + p)中,搜索格式,然后选择格式化文档。然后选择 Prettier - Code Formatter.

注意:如果您没有看到选择默认格式的提示,您可以在“设置”中手动更改它。将编辑器:默认格式化程序设置为 ebsenp。

这是完整的解决方案: 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.

不知道为什么,但将 Default Formatter 设置为 ebsenp.prettier 对我不起作用。但是我发现了一个类似的命令。

  1. ctrl + shift + p
  2. 格式化文档
  3. 配置默认格式化程序
  4. 选择更漂亮的
  1. 通过单击 vs 代码侧栏左下角的齿轮并从菜单中选择设置,或按 Ctrl+,

    打开设置
  2. 在设置窗格的右上角,点击打开文件图标(如果悬停,工具提示将显示为 'Open Settings (JSON)'

  3. 将以下行添加到设置 json:

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

我找到的最简单的方法是:

  1. Right-Click 在您要格式化的文件上

  2. Select

    Format Document With ...
    


  1. 您将获得 drop-down 不同的格式化程序。最终参赛作品将是

    Configure Default Formatter...
    


  1. 选择后,如果重复,您将看到带有

    标记的默认格式化程序
    (default)