How to format code in Visual Studio Code on Windows

后端 未结 6 1333
臣服心动
臣服心动 2021-01-03 18:38

How can I format code in Visual Studio Code in the last update on Windows.

I tried Ctrl+ K, Ctrl + D doe

6条回答
  •  [愿得一人]
    2021-01-03 18:40

    Formatting any document in Visual Studio Code requires one to install a formatter plugin, like Prettier - Code formatted by Esben Petersen.

    • Install the plugin: Prettier - Code formatter from the Extensions window in Visual Studio Code.

      • You can open the extensions window from the left aligned sidebar or simply by pressing Ctrl + Shift + X
    • Post installation, from the required page you can try the below

      • Right click and choose Format Document; or
      • Try Alt+Shift+F on Windows

    The document should now be properly formatted.

    • PS: You can set "Prettier - Code formatted" as the default formatter for Visual Studio Code by performing the following:
      • Open Settings by pressing Ctrl + , and search for editor.defaultFormatter. Choose esbenp.prettier-vscode from the list and Save. By default, now formatting any document with the above steps will use Prettier as the default formatter.

提交回复
热议问题