Visual Studio 2019 closing curly brace not under the opening brace (it's fully left aligned instead)

visual studio curly braces same line
code alignment in visual studio
visual studio fix brackets
visual studio auto format
visual studio format html

Recently the closing curly brace start to align on the fully left instead of under the opening brace, but only when the braces are empties :

(I'm in Visual Studio 2019, in C# code) Steps :

write this :

namespace myNameSpace
{
    class myClass
    { }
}

Then hit return while in between the class braces, it did this :

namespace myNameSpace
{
    class myClass
    { 
 }
}

Note the class closing brace not being under the opening one.

How can I have this instead, where is the formatting option ?

namespace myNameSpace
{
    class myClass
    { 
    }
}

Thanks,

I've seen this happen before in various versions of VS. It's not really reproducible, but sometimes for no explainable reason, VS just starts acting this way.

There are a couple of ways to handle this. The quick fix is to just hit

ctrl+k+d

And that will auto-align all of the code (and comments) on the open file. While that will fix the misaligned brackets after the fact, it won't stop VS from still doing it.

If it gets too annoying (which it can!) then what you can do is a ctrl+a to copy everything. Then paste it into a text file (so you don't accidentally lose it). Remove the file from the project. Then, delete the actual file from the working folder. Close and re-open VS. Then re-create the file and paste all of the contents back into it.

That should solve the problem.

C# braces indent incorrectly if brace completion is disabled , If you turn off brace completion in C#, then if you get: After typing the closing brace, as soon as you press the up arrow, the cursor The bug is, that it is indenting and thinks you are opening a new code We must not stick to thinking that we must always use visual studio, even when it doesn't work well. My problem, although I do not know the name, is where when I press enter in the middle of a set of curly braces after, for example, an if statement, instead of formatting correctly in the right way, the closing curly brace will go to the start of the first line and the opening curly brace will stay there, just like how normal text editing, in

Indentation and bracing styles tend to be religious issues. When you move from team to team, you end up having to learn the local brace/indent style. There's a whole Wikipedia article on it (https://en.wikipedia.org/wiki/Indentation_style).

In Visual Studio, you can setup your preferred brace/indent style. My guess is that your bracing/indentation is busted and needs to be reset.

To get there:

Tools ->> Options ->> Text Editor ->> C# ->> Code Style ->> Formatting ->> Indentation

Once you are there, if thing are the way you want them, change them to something else before OK-ing out of the dialog. Then do it again and change it back. If they don't match your desired style, just change things (the idea being - you need to make a change so that your change gets saved).

Good luck

Cannot type close brace, Closed - Fixed fixed in: visual studio 2017 version 15.8.2windows 10.0visual studio When I press AltGr+Shift+Close brace, instead of type the close brace, it select all visible text. good, old-fashioned ALT+125 (or ALT-123 for open brace​). 2 Jane Wu [MSFT] Apr 02, 2019 at 01:57 AM Christian Nilsson. Braces and brackets are displayed in black after vs upgrade of vs 2019 visual studio 2019 version 16.2 windows 10.0 gabrielw reported Aug 21, 2019 at 07:03 AM

Ok, it’s appeared, but I might be wrong, that the smart tab management had changed lately and that now it is no longer inserting tab at the beggining of a second empty line in a bloc (like some other code editor). Therefor leaving only a space on the second line, leading to my "problem".

I always used smart tab indenting for all languagse and then lately it seen to have changed then causing this. So the solution for me was to go back to Block Indenting and it work well. I don’t know what other differences that may cause, but...

NOTE: That this only occur if using the Keep tabs option

Thanks all, your comments lead me to a solution (or at least a work-around).

curly-brace formatting doesn't respect options in VS · Issue #16581 , curly-brace formatting doesn't respect options in VS #16581. Open .com/​content/problem/11450/javascript-auto-format-of-function-curly-brace-not.html do not place the opening brace on a newline in VS if there isn't a matching closing brace. aozgaa added Bug Visual Studio labels on Jun 16, 2017. Thanks for you reply but that's not what I was looking for. Pressing Ctrl+Shift+] is even more complex than pressing the 'End' key. I am looking for a way to go to the closing bracket using the 'Enter' key, for instance, just like you can do in Eclipse.

Auto-formatting as you type looks to be turned off by default in Visual Studio 2019. To auto-format your code, go to Tools -> Options -> Text Editor -> C# -> Code Style -> Formatting and select the option Automatically format when typing then select your preferences as to when auto-format should be triggered. Example screenshot:

Auto-format option in Visual Studio 2019

Finding Matching Brackets in C# -- Visual Studio Magazine, There's a third option that not a lot of developers know about: Place your cursor on the bracket you're trying to match (open or close) and press  Is there a way in Visual Studio 2008 to go from a closing brace to its opening brace? I've found a fair amount of stuff about highlighting the brace, but nothing about moving the cursor to it. (VB.NET version of this Question: Keyboard shortcut for Jumping between "If/End If")

Soft Computing for Problem Solving 2019: Proceedings of SocProS , 2.2.3 Arduino IDE Arduino IDE software is an open-source integrated require an external library to be added before use; otherwise, the sketch will not compile. a curly bracket), namely the loop function and runs until it reaches the closing in this project to test the C# GUI software that was written in Visual Studio 2018. The following instruction shows how to change the background color of the matching braces and its rectangles. Click on the picture and take a look at the braces in the source code! Open Visual Studio --> Tools --> Options. To change the backgroundColor follow the steps in the picture below!

Insert () and Closing } ), Beginning with Visual Studio 2013, Visual Studio can also insert closing Disable "Automatic Brace Completion" for the current programming language in the between the parentheses if your selection takes an argument, and after if not. Curly Brace for Visual Studio Code. Bring your favorite robot companion from Cave Story to your favorite code editor! Curly Brace will show up after each closing bracket. Curly Brace is the property of Daisuke "Pixel" Amaya. License. MIT.

Why do C# developers newline opening brackets? [closed], Everyone did the curly-brace-on-newline thing. The brace at the end of the line is the ancient K&R C standard, from Brian Kernighan and Dennis Ritchie's book The C Programming Language, which So in that sense, C# is not "based on Java. As for why this is the default in Visual Studio, I don't know. In Notepad++ for example when your cursor is next to a brace it will highlight the corresponding opening or closing brace on screen. Check out the link below for a example as to what I mean.

Comments
  • I tried in VS2019 and cannot reproduce your problem. I get the desired alignment of braces. (With or without a semicolon after the inner closing brace!)
  • Hey Robin. I apologize for the people who downvote you and marked the question as "should be closed" without giving you an explanation. That's uncalled for. I think this is a very legit question. I voted you back up and provided what I hope is a helpful answer.
  • Ctrl E+D will format the whole doc.
  • @Robin Are you using any Extensions?
  • You may need to do a little reading to get to the bottom of it... docs.microsoft.com/en-us/visualstudio/ide/… Here is a way to customize the .editorconfig docs.microsoft.com/en-us/visualstudio/ide/…
  • Sounds like one of those special features that makes VS such a wonderful IDE!
  • @Adrian Yes, exactly! I don't see it very often, but when it pops up, it's incredibly vexing. I go through the steps I outlined above while cursing under my breath.
  • And Stack Overflow is as good a place as any to find a quick fix (thus saving on a lot of self-harm and hair-pulling). Don't get the attitude of some folks here who like to vote down and/or close such questions. Quite tribal, sometimes?
  • @Adrian, agreed. The number of spiteful users on here who get off on downvoting people is sad. This is supposed to be a "let's help each other!" community.
  • @CaseyCrookston..Sometimes its warranted...but when its you getting the downvotes...man it smarts. I got banned for 9 months for asking questions. I almost grit my teeth when I need an answer now
  • Good advice...the key is to just make a change and then change it back.
  • This was driving me insane, thank you.