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

后端 未结 10 1513
故里飘歌
故里飘歌 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:16

    Try install the following ext then use shortcut: Ctr+; (Cmd+;)

    0 讨论(0)
  • 2020-11-30 03:17

    Ctrl+Shift+P and open Preferences:Open keyboard shortcuts (JSON) in VS Code

    and insert

    {
        "key": "tab",
        "command":"cursorEnd",
        "when":"editorTextFocus"
    }
    

    tab is optional, ofc. Put whatever you want from the keys on the keyboard.

    0 讨论(0)
  • 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!
    0 讨论(0)
  • 2020-11-30 03:19

    Now there is an extension called Colonize:

    Shift+Enter Insert semicolon at the end of line and continue on the same line

    Alt+Enter Insert semicolon at the end of line and continue on the new line

    Ctrl+Alt+Enter Insert semicolon and stay at the same position

    0 讨论(0)
  • 2020-11-30 03:19

    There is no way to do it by default that I could find. I just had to make do as best I could.

    I ended up adding a binding via File>Preferences>Keyboard Shortcuts, and then pressing ; after the shortcut. Having the semicolon is part of the binding is as close as I could get... at least my finger is already over that key

    // Place your key bindings in this file to overwrite the defaults
    [
        {
            "key": "ctrl+;",
            "command": "cursorEnd",
            "when": "editorTextFocus"
        }
    ]
    

    This simply means that Ctrl+; brings you to the end of the line, and then tap ; again.

    0 讨论(0)
  • 2020-11-30 03:23

    I know this is a really old post but Prettier - code formatter for vs code adds the semi colon (amongst other formatting).

    ext install esbenp.prettier-vscode

    0 讨论(0)
提交回复
热议问题