Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio editor - extend selection to the next larger code block?

In Visual Studio 2010, is there any way to quickly extend the selected text to the next logical code block? For example, if my cursor was here:

location of cursor

And I hit some magical keyboard shortcut, it would select the entire string:

Example of selected string

Hit it again, and it would select the next larger logical block of code:

Example of selected code block

And so on. Does this exist? My google-fu seems to be failing me..

like image 207
lambinator Avatar asked Oct 26 '11 17:10

lambinator


People also ask

How do you expand a selection in VS Code?

Shrink/expand selection# Quickly shrink or expand the current selection. Trigger it with Shift+Alt+Left and Shift+Alt+Right.

How do I collapse and expand code in Visual Studio?

CTRL + M + O will collapse all. CTRL + M + P will expand all and disable outlining. CTRL + M + M will collapse/expand the current section.

How do you select a block of code in Visual Studio?

You can select blocks of text by holding Shift+Alt (Shift+Option on macOS) while you drag your mouse. A separate cursor will be added to the end of each selected line.

What does Ctrl B do in VS Code?

ctrl + b is bound to Add Function Breakpoint by default. You can edit the shortcuts from File->Preferences->Keyboard Shortcuts . Show activity on this post. File > Preferences > Keyboard Shortcuts will show you a list of shortcuts.


2 Answers

Visual Studio 2017 15.5.2 appears to have this feature built-in after it was first hinted at in a Visual Studio 2017 Preview blog post (see section "Smart Code Editor").

Invoking it can be done by going to Edit > Advanced > Expand Selection or by binding the Edit.ExpandSelection command to Ctrl+W (actually the new default if you start without any previous keybindings).

Shrinking / contracting the selection is possible as well, look for Edit > Advanced > Contract Selection or the Edit.ContractSelection command (default Ctrl+Shift+W).

like image 155
JBert Avatar answered Sep 19 '22 23:09

JBert


In ReSharper, this is extend selection and the shortcut is CTRL-W. Not sure of a non-ReSharper solution.

like image 43
Kirk Woll Avatar answered Sep 22 '22 23:09

Kirk Woll