How can I configure V.S. Code to auto close brackets?

Viewed 474

V.S. Code: Auto Closing Brackets

    "I would like if V.S. Code automatically closed brackets for me when I insert opening brackets into my code."




EXAMPLE:
    Normally when the Left-Bracket key — i.e. { — is pressed inside of any arbitrary software, asingle left bracket is added to the document, with the cursor positioned to the right of it, as is demonstrated below.

{ |

NOTE: "The | is used to show the position of the cursor."


    When the left-bracket key is pressed, I would perfer that V.S. Code adds a pair of brackets with the cursor positioned between them, as is demonstrated below.

{ | }

NOTE: "The | is used to show the position of the cursor."


1 Answers

Getting VSCode to Auto Type Closing Brackets

You need to add the configuration below to your settings.json file, preferably the one in your workspace as tools & extensions override the workspace setting.json file less often.
   "editor.autoClosingBrackets": "always"

If its still not working, then you need to restart VSCode with all extensions disabled. Make sure the configuration above is correct and then try again in order to make sure the setting isn't being overridden by an extension.

If you just can't find the configuration the above should work fine, however, if you are experiencing an issue, try running VSCode with extensions disabled and see if that resolves the problem. I had an issue in the past where an extension caused auto-closing bracket issues in my instance of VSCode. Not to mention, when troubleshooting something in VSCode, the first thing you should always to is test if the issue occurs when extensions are disabled, this way you can either rule out extensions, or know that it is an extension.

It should work fine with all extensions enabled, but I had a co-worker, who couldn't get the brackets to work and it was because of a recent update added to one of his extensions.

Related