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
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.
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:
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.
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.)
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!