Jul
30
2008

ReSharper Tip of the Day: Templates Revisited, and the Surround With

Today’s ReSharper Tip of the Day is a guest posting from Josh Buedel,  It is a great tip that extends ReSharper’s use into the CSS and HTML space.

Resharper templates come in two flavors:  Live Templates which are invoked by typing keyword and pressing tab, and Surround With Templates, which are invoked against the current selection.

 

Did you know that R# templates can be used in any file type?  You aren’t limited to just the sections of files that it understands.  For example I’ve built up a handful of templates for Aspx pages.  Surround With templates are particularly useful in a markup language like html. 

 

I first invoke my custom Surround With CSS Comment (Ctrl+Alt+J). 

 

Then I type the keyword data and hit Tab, which invokes a custom live template for databinding code.

 

In this one I select all that and again do a Surround With, this time using my custom Link Tag (<a/>) template.

 

Lastly, I have this generic tag inserter. 

Notice how as I change the name of the opening tag, the end tag is updated right along with it.  I accomplish this by repeating my template variable (which I have named $TAG$) within the template.  Once the template mode is exited the cursor ends up positioned inside the opening tag, but just before the closing > character.  This is by design, by using the predefined $END$ variable, and is right where I would need to be to insert an attribute should one be needed.  Here’s the complete template for this:

 

Written by Mark in: ReSharper Tip of the Day | Tags:

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Kredit | TheBuckmaker