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

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

    Visual Studio Code doesn't appear to directly support adding a semi-colon to the end of a line via a keyboard shortcut, meaning it'll need a custom extension to support it. Fortunately, Sergii Naumov has created one for us, named (appropriately) 'Trailing Semicolon'.

    To install this extension:

    1. Launch Visual Studio Code
    2. Press "Ctrl+P" (or "Command+P" on the Mac)
    3. type "ext install Trailing Semicolon" to search for the extension
    4. With the extension visible below the search box, click the Install Extension icon in the bottom right of the extension. (It's a cloud with an arrow pointing down...)

    You will need to restart Visual Studio Code to enable the extension (Visual Studio Code should prompt you to restart once the extension has been successfully downloaded.)

    According to Sergii, the default keybinding for the extension is "cmd+;". On my Mac, this meant pressing "Command+;", which worked great.

    On my Windows 10 PC, I tried several key combinations ("Window+;" "Ctrl+;" "Alt+;" etc.), and nothing worked. I opened the Keyboard Shortcut preferences (File > Preferences > Keyboard Shortcuts) and searched for the new extension. I found it listed at the end of the keybindings:

    { "key": "win+;",                 "command": "extension.trailing-semicolon",
                                      "when": "editorTextFocus" }
    

    The "win" key binding apparently doesn't work. I copied this binding to the keybindings.json file, changed "win+;" to "ctrl+;" and it worked like a charm!

    Hope that helps.

提交回复
热议问题