Reputation: 53
When I place an open brace in Visual Studio 2017 (C#) the cursor automatically goes to the next line to the left of the end brace. Like this (period as cursor):
if() {
.}
I'd like the cursor to automatically be on its own line like this (period as cursor):
if() {
.
}
Does anybody know how to make the cursor automatically go where the period is in the second example?
Upvotes: 5
Views: 864
Reputation: 1029
If you want to automatically place the cursor inside the curly braces (i.e. without any shortcut), you can enable that from Tools -> Options -> Text Editor -> C/C++ -> Formatting -> (check) Automatically format braces when they are automatically completed
.
Of course, this is for C/C++. I don't use C# so I haven't tried for C#, but it should be similar, probably Tools -> Options -> Text Editor -> C# -> Code Style -> Formatting -> (check) Automatically format block on }
(please correct me if I'm wrong).
Upvotes: 0
Reputation: 8792
When you are at state 1 from your example use Ctrl + Enter.
This sends the line you are at one level down but keeps the cursor at current position. Effectively that will get you from state 1 in your example to state 2 in your example.
Upvotes: 3
Reputation: 1999
Meanwhile you are inside the parentheses of if (.) then use:
Ctrl + Shift + Enter
I use Resharper hotkeys so you might have different combination find it out by going under Environment -> Keyboard and show commands containing Edit.LineOpenBelow.
This command is responsible for that action.
Upvotes: 1
Reputation: 447
Not sure because I am on VS 2013, but what you're looking for is probably in
Tools --> Options --> Text Editor --> C# --> formatting --> New Lines
Upvotes: 1