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:
And I hit some magical keyboard shortcut, it would select the entire string:
Hit it again, and it would select the next larger logical block of code:
And so on. Does this exist? My google-fu seems to be failing me..
This is build-in feature in Visual Studio 2017 (current version 15.8.1)
Expand selection to containing block
Ctrl + Shift + Alt + +
Shrink selection to previous block
Ctrl + Shift + Alt + -
Also you can expand/shrink selection progressively by
Shift + Alt + + - Expand
Shift + Alt + - - Shrink
In the Visual Studio Menu Bar (Top) go to
Tools > Options
Select
Environment
>Keyboard
as shown below. Search forSelectCurrentWord
and highlight the entry that comes up. Click the remove Button next to "Assignment".Search for
WordNextExtend
, highlight the entry and add CTRL + W under "Press Shortcut Keys". Click the Assign button.Usage: move the cursor to any word, press CTRL + Left and subsequently consecutively CTRL + W.
That's it. There is a great benefit to using the same scheme as JetBrains Products. Enjoy!
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 theEdit.ExpandSelection
command toCtrl+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 theEdit.ContractSelection
command (defaultCtrl+Shift+W
).Expand:
Alt + Shift + =
Reverse:
Alt + Shift + -
taken from here
In Visual Studio 2015 it's possible using a free "Hot Commands" extension: https://visualstudiogallery.msdn.microsoft.com/f073b573-c9a3-4104-a682-bd7a6c1023a6
Use "Expand selection" command.
Ctrl-W will select an entire word in Visual Studio. I cannot seem to find an option to select an entire code block.