Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically add semicolon to end of line in Visual Studio 2019

My question is similar to How to add semicolon to the end of the line in visual studio code, but for Visual Studio 2019. The extensions mentioned in the answers, and others I've been able to find, only work in VS Code or earlier versions of VS it seems.

As @gavin so eloquently put it in that question:

... in vs code, when you write a method call, it automatically closes the open parameter for you and your cursor ended up before the ). Now if you want to write a new statement, you literally have to take your right hand off the jkl; position and click on the end or the right arrow key and then take your right hand back to the jkl; position to type the semicolon. I use shift + enter and it saves me around half a second for each statement to reposition my right hand

like image 254
Sandra Avatar asked Aug 07 '19 17:08

Sandra


People also ask

How do you add a semicolon to the end of a line in Visual Studio code?

Settings -> in Search bar type: 'semicolon' -> change values to 'insert' for both JS and TS, save and close. Now every time on save, VSCode will look for missing semicolons inside the file you're in and append them.

What is a trailing semicolon?

The trailing semicolon is the last semicolon in a declaration block and it is optional. This rule ignores: Less mixins. trailing // comments.

How do I add a semicolon to the end of a 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 Show activity on this post. 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.

What is the point of the semi-colon extension?

When the extension moves the semi-colon to the end of the line it also moves your cursor to the next line, thereby making your typing very fluid without having to manually put semi-colons explictly at the end of each line or even having to hit the enter key to move to the next line.

How do I install trailing semicolon in Visual Studio Code?

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

Do you have to close the bracket when Type A semicolon?

No need to close the bracket or type the semicolon. It's supposed to place a semicolon even when your cursor is no at the end, to save the trouble of pressing End. It's just a minor convenience thing, I'm just spoiled


3 Answers

  1. Install Productivity Power Tools 2017/2019 (if it is not already installed)
  2. Press Shift+Enter to add ";" automatically at end of the line:

enter image description here

like image 76
Maicon Heck Avatar answered Sep 25 '22 13:09

Maicon Heck


I noticed that in the latest version of VS2019, if you are within parentheses and you type a semicolon (without any special shortcuts), it automatically moves it for you towards the end of the brackets where it should be. I don't have any special extensions installed for that.

It doesn't work for every situation. It seems that you need to be within brackets.

like image 28
Abdurrahman Avatar answered Sep 22 '22 13:09

Abdurrahman


Simply I used prettier code formatter and it fixed all my problems.

like image 40
ismadev Avatar answered Sep 22 '22 13:09

ismadev