Visual Studio editor - extend selection to the nex

2019-06-15 02:28发布

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..

7条回答
狗以群分
2楼-- · 2019-06-15 02:30

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

查看更多
贪生不怕死
3楼-- · 2019-06-15 02:31

In the Visual Studio Menu Bar (Top) go to Tools > Options

Select Environment > Keyboard as shown below. enter image description here Search for SelectCurrentWord 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!

查看更多
女痞
4楼-- · 2019-06-15 02:33

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).

查看更多
聊天终结者
5楼-- · 2019-06-15 02:36

Expand: Alt + Shift + =

Reverse: Alt + Shift + -

taken from here

查看更多
仙女界的扛把子
6楼-- · 2019-06-15 02:44

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.

查看更多
Animai°情兽
7楼-- · 2019-06-15 02:46

Ctrl-W will select an entire word in Visual Studio. I cannot seem to find an option to select an entire code block.

查看更多
登录 后发表回答