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

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

    SHORT ANSWER:

    Shift+Enter

    LONG ANSWER:

    As ST7 mentioned, you can add the Colonize extension, but apparently Visual Studio (I'm currently using 2017) contains Shift+Enter shortcut by default, which unlike Colonize, continues on the new line.

    0 讨论(0)
  • 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.

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

    I wrote an extension to mimic IntelliJ's complete statement. Pressing ctrl+; (cmd+; on mac) appends ; to the line end, and moves cursor to line end. If the line already ends with ;, pressing ctrl+; just moves cursor to line end.

    There is also experimental support for complete structures like class, interface, function, if, switch, for, and while. (Not understanding semantic of languages, so it may not work as you expected.)

    You can install it as VSIX at GitHub.

    The version vscode marketplace is outdated. (Unfortunately my M$ account has been suspended, thus I cannot update it.)

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

    It's in Visual Studio's Preferences. Solution from sbi's answer here:

    • Go to Tools/Options/Environment/Keyboard.
    • Switch the "Use new shortcut in:" dropdown to "Text Editor".
    • Pick the Edit.BreakLine command.
    • In the Press shortcut keys edit pane press Shift+Enter.

    Worked for me!

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