Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically format code in Visual Studio Code

I'm a long time visual studio developer and am stating with VS Code.

I found the Format Code shortcut (Shift + Alt + F) but I want it to run automatically whenever I press ;. Is there a configuration for that?

like image 689
Noam Avatar asked Apr 06 '17 06:04

Noam


People also ask

How do I enable auto format in VS Code?

VS Code Auto Format On SaveOpen Visual Studio Code editor. Click the “Settings” gear icon in the bottom-left corner. Search “Formatter” and click the “Editor: Default Formatter” option. From the drop-down menu, select whichever code formatter you want to use.

What is the fastest way to format code in Visual Studio?

In the default configuration for Visual Studio Code, the command can be run using the shortcut Alt+Shift+F. To format a range, in an already opened project, open the document that you want to modify, select the specific range to format, right-click, and select Format Selection.


1 Answers

You can choose one of the below options

"editor.formatOnType": false, "editor.formatOnPaste": false, "editor.formatOnSave": false 

Or create a custom keyboard shortcut by editing editor.action.formatDocument. But I AFAIK there is no option to execute the command whenever you press ;. You can set a keyboard shortcut, but I guess you're not able to write ; anymore then :D

like image 80
Sebastian Sebald Avatar answered Oct 11 '22 02:10

Sebastian Sebald