Reputation: 1259
Is there a shortcut to jump outside of a code block, right after a closing brace }
of a current code block?
Let me explain.
Let's say there's a method:
private void Button_Click(object sender, EventArgs e)
{
if (enableCheckbox.Checked == true)
{
if (labelToChange.Text == "Right")
{
labelToChange.Text = "Left";
}
else
{
labelToChange.Text = "Right";
}
}
}
And my cursor is somewhere on the line labelToChange.Text = "Left";
.
I would like to make it to jump to the closing brace }
of current if (labelToChange.Text == "Right")
code block by pressing Ctrl+]
.
Then if I press Ctrl+]
again, I would like it to jump to closing brace }
of if (enableCheckbox.Checked == true)
code block.
And then if Press Ctrl+]
for the third time in a row, I would like to jump to the closing brace }
of a code block of a method private void Button_Click(object sender, EventArgs e)
.
Here's what I'm trying to achieve in motion:
I was managed to achieve this behavior in WebStorm and PhpStorm by using a macro:
It goes to the end of code block and then it goes to the end of the line, so it stops outside of closing brace.
Comes very handy all the time when I am working with multiple code blocks: if/else, writing methods, anything, I use it all the time in WebStorm and PhpStorm.
Is there a way to achieve this in Visual Studio?
I know about default Ctrl+]
shortcut, the problem with Edit.GoToBrace
command is that it goes to the closing brace }
only when cursor is at the opening brace {
but not when cursor is anywhere else inside the code block.
PS Yes, I did check similar threads:
None of them help me to find a solution to my problem. Please help.
Upvotes: 5
Views: 4147
Reputation: 687
According to this answer.
I am using VS2017, and had tested default shortcut keys: Shift+Alt+[, it can jump to the head of containing block.
This default shortcut is for EditorContextMenus.Navigate.GoToContainingBlock
.
It works for me.
It is still working in VS2019
I found an extension for visual studio to achieve the enhanced "Edit.GotoBrace" command.
Please check it out. Here's FeinBrace!
I have tested in my IDE(visual studio 2017).
It works in
other functions are not working.
And the extension has been not updated for a while. There are more related extension for visual studio code. But I don't know is it suitable for visual studio.
Upvotes: 3