Reputation: 305
My problem is when I create a new method it looks like this...
public string firstName {
}
The cursor is stays right before the }, and then if I type more code it looks like...
public string firstName {
get;}
And...
public string firstName {
get;
set;}
Then I have to press enter for it to look like...
public string firstName {
get;
set;
}
What I want for it to look like from the beginning is...
public string firstName {
<cursor here>
}
I've looked all over in the formatting options, and can't seem to find anything. I used to get it like this before, and I don't know what happened that caused this issue. It's very annoying! Please help.
Upvotes: 7
Views: 10194
Reputation: 11
I had this problem in the latest VS2022 too but for C++, not C#.
I managed to fix it by enabling "Automatically format braces when they are automatically completed" in C/C++ -> Code style -> Formatting -> General
Upvotes: 1
Reputation: 1
In Visual Studio 2022, Try to disable some or all checkboxs at:
Tools > Options (CTRL + ,) > C# (or another language) > Code Style > Formatting > New Lines
But, if the problem is the cursor behind the close braces, I solved it by check Leave block on single line and Leave statements and member declarations on the same line at:
Tools > Options (CTRL + ,) > C# (or another language) > Code Style > Formatting > Wrapping
Maybe other version of Visual Studio have different settings location, You could explore it.
I hope that helps :)
Upvotes: 0
Reputation: 399
Try this. Tools->Options->Text Editor->C#->Formatting->New Lines. In there, under New line options for braces, make sure those are all checked. That's what determines where the braces go when you type the left brace and then hit enter.
edit: That didn't do it, but second suggestion of Wrapping then checking "Leave block on single line" did do it for OP.
Upvotes: 14