Search code examples
visual-studio-2010curly-braces

Visual Studio 2010 - Curly Braces auto-align has changed, how do I fix this?


Update: Since I see this is one of my most looked at questions, now a few years later I should point out what I found to be the most common cause of this problem: bad syntax elsewhere in your code. 100% of the time I've had this happen, it was because I'd forgotten a curly brace for another block of code, or I had a dangling if, or an earlier line of code I didn't finish. Check for IDE errors first for something like ") or } expected"

Original Question:

I feel like this is an all time dumb question to ask, but I have no idea how to fix this and google is turning up nothing.

In visual studio, when I type:

try {

}

VS would automatically reformat it to

try
{

}

But now it's just leaving it at the first one. I assume I accidentally hit a hotkey or something. Help me fix this please?


Solution

  • 9 times out of 10 this problem is caused by bad code elsewhere on my document. Either I'm missing a ; on a line, or perhaps a closing }. Visual Studio is unable to figure out what I'm trying to write in code and thus it's unable to format. Check for compiler errors, fix them, and then press Ctrl+K then Ctrl + D to make Visual Studio reformat the current document (your hotkeys may vary, depending on the version of Visual Studio and your settings).