Geeks With Blogs
Doug Butscher Nothin' but .NET!

Just stumbled across some pretty cool functionality with Jet Brains ReSharper 4.0 (you may already be familiar with it, but who cares, it’s still cool!)


Basically, ReSharper has a Surround With tool that allows you to surround a selection of code with… more code. It comes with a bunch of predefined templates, like if..else, using, while, try..catch blocks, but you can edit existing templates and also create and organize your own custom templates.

To get to the Templates Explorer, select ReSharper > Live Templates… from the file menu. Select the Surround Templates tab. Once you’re in there, click on the New Template icon and a new File will open in the IDE, and filled by default with the text $SELECTION$. This is the code selection that will be wrapped when your template is applied. Below is a cap of a sample wrapper with some sample template code.



























To apply the template, highlight your code selection









Select ReSharper > Code > Surround With… from the File menu (or CTRL + E, U).

























Choose More… from the menu. Find your  template in the dialog and click OK.

























When your template is applied, your selection will be replaced with the wrapped text, like below.










This is just the basic stuff. You can categorize your templates, choose which language they will apply to, add them to the quicklist (so they get assigned a quick key), and a whole bunch of other stuff that can be found on the ReSharper help pages.


Posted on Thursday, October 15, 2009 6:00 PM | Back to top

Comments on this post: ReSharper | Surround With

# re: ReSharper | Surround With
Requesting Gravatar...
Thanks for this, that is a really handy tip. I will commit CTRL + E,U to memory now.
Left by Garry Pilkington on Oct 19, 2009 4:19 AM

# re: ReSharper | Surround With
Requesting Gravatar...
nice, very powerful
Left by Jack on Oct 20, 2009 4:08 AM

# re: ReSharper | Surround With
Requesting Gravatar...
This is a handy feature. I just set up a template in Resharper yesterday to add the boilerplate for a unit test. Could I live without Resharper? Yes. Would I choose to? No Sa!
Left by Bodie on Oct 20, 2009 9:14 AM

# no teme
Requesting Gravatar...
Dear Author !
On mine the theme is rather interesting. Give with you we will communicate in PM.
Left by Okskiy on Dec 18, 2009 6:18 PM

# re: ReSharper | Surround With
Requesting Gravatar...
I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
Left by nexon game cards on Jan 11, 2011 5:10 PM

# re: ReSharper | Surround With
Requesting Gravatar...
I like your post & I will always be coming frequently to read more of your post. Thank you very much for your post once more.
Left by Cars Ghana on Feb 23, 2011 7:20 AM

# re: ReSharper | Surround With
Requesting Gravatar...
Interesting blog just bookmarked it for later reference.
Left by Dubai car rentals on Feb 27, 2011 4:25 AM

Your comment:
 (will show your gravatar)

Copyright © Doug Butscher | Powered by: