Friday, July 3, 2009

DevTnT 6 – ReSharper: Expanding the selection with Ctrl+W

In a previous post, Sebastian drawed our attention to a nice selection expansion feature of ReSharper. I also think this feature is cool, and want to present it here in more depth.

Visual Studio by itself supports the expansion of the current selection in a text editor window by pressing Ctrl+W.

With this command you can change a current selection like this …

Cursor in source code before expansion

… to a selection of the whole word:

Selection in source code after expansion

 

If your existing selection spans several words like this …

Selection in source code spanning two words

… after pressing Ctrl+W you end up with the word selected that is at the end of the selection:

Selection in source code after expansion

(Funnily, if you made your selection from right to left the left word gets selected:

image )

Further pressing Ctrl+W does not do anything more.

 

Text Expansion With ReSharper

ReSharper has taken that expansion feature to the max (that’s why we love this tool!).

Beginning with no selection …

image

… by pressing Ctrl+W ReSharper selects the whole word:

image

But now, you can press Ctrl+W several times more to expand the selection to several areas, one larger than the one before.

From the single word selection you get the selection of the whole string without the quotes:

image

Then ReSharper selects the string including the quotes

image

… then the whole concatenated string from the beginning of the expression

image

… and then incrementally the whole string expression line by line:

image

image

 

And so it goes on with every stroke on Ctrl+W until the whole file content is selected:

The whole statement

image

… the whole block without the braces

image

… the block including the braces

image

… the whole member

image

… the type’s content without the braces

image

  … the whole namespace’s content without the braces

image

… the whole namespace

image 

… and finally the complete content of the file:

image

As you may guess, the whole stuff can be done in reverse order pressing Ctrl+Shift+W.

Good to know!

No comments:

Post a Comment