cost
cost

Reputation: 4480

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?

Upvotes: 2

Views: 7428

Answers (4)

cost
cost

Reputation: 4480

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

Upvotes: 0

CJBS
CJBS

Reputation: 15685

In addition to the default Visual Studio settings mentioned, for ReSharper users, this is configured via:

ReSharper [menu] -> Options

In the Options dialog, navigate to Environment -> Editor -> Editor Behavior -> "Auto-format on closing brace". See image:

enter image description here

Upvotes: 0

Craig G.
Craig G.

Reputation: 157

Tools->Options->Text Editor->C# (or whatever language)->Formatting->New Lines

Select the options you want.

If you have Power Commands installed you can then go to the Tools->Options->Power Commands and make sure "Format Document on Save" is selected.

Whenever you save the edited file the Curly Braces will be auto aligned.

Upvotes: 2

John Kalberer
John Kalberer

Reputation: 5800

Tools->Options

Click Text Editor -> Whatever language -> Formatting

Upvotes: 3

Related Questions