How to add semicolon to the end of the line in visual studio code

后端 未结 10 1540
故里飘歌
故里飘歌 2020-11-30 02:35

I press Shift+Enter, but not working, Ctrl+Enter start a new line, but not add semicolon at the end of previous line. Is there a

10条回答
  •  一整个雨季
    2020-11-30 03:18

    I just started using Visual Studio Code and felt this requirement myself yesterday. After a quick google search I found this nice extension called "Prettier". Being a little new to VSCode it took me a few hours to get it all setup but it works like a charm now. Here are the steps and my setup. I hope it helps others.

    My coding environment: VSCode running on a Windows 10 desktop environment connecting to my codebase SMB share hosted on my development machine which is running Ubuntu server 18.04.

    Solution Steps

    • Install node on the Windows desktop
    • Run, npm install -g prettier
    • Install the Prettier extension in VSCode
    • Edit the settings.json file for VSCode and add the following

          "editor.defaultFormatter": "esbenp.prettier-vscode",
           "[javascript]": {
                "editor.defaultFormatter": "esbenp.prettier-vscode"
           }
          // Set the default
          "editor.formatOnSave": true
      
    • Add the .prettierrc file at the root of my codebase on the ubuntu host (e.g.: /var/www/html/tutorials) with the following basic styling configuration

        {
          "semi": true,
          "trailingComma": "all",
          "singleQuote": true,
          "printWidth": 80
        }
    
    • Restart VSCode and open the code file
    • Use the existing VSCode keyboard shortcuts to apply formatting to the entire file (Ctrl+K Ctrl+F) or to a selection (Shift+Alt+F)
    • Or simply saving the file Ctrl+S adds the formatting while saving the file with no additional work required
    • Viola!

提交回复
热议问题