Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



ReSharper Live Templates Distilled

If you are a ReSharper user (I know many of you are) and you are NOT taking advantage of the LiveTemplates feature, you are really not maximizing your productivity.

Today I thought I would do a quick demo on how to create and use a LiveTemplate.  Sit back, relax and learn how to make yourself more productive.  For some info on LiveTemplates from JetBrains check this out.

Steps to creating your LiveTemplate

  1. Determine code that you create all the time
    For me I am always typing out Assert.That( XYZ, Is.EqualTo( ABC ) ) in my tests, so lets turn this into a LiveTemplate
  2. Launch the LiveTemplate Explorer 
    Reshaper -> LiveTemplates

    LiveTemplateExplorer
  3. Determine where you want to place your new template
    I would suggested you put it under the "User Templates" section, but your call.
  4. Select where you want to put your template and click the new button
    This should open up a new editor window, this is where the fun begins.
    1. Provide a Shortcut.  This is what you will type to produce the code in the LiveTemplate.  I would suggest you come up with a standard naming scheme to make life easier, but again your call.
    2. Provide a Description
    3. Copy and Paste in your code you want to use.
    4. Determine if you want any variables (dynamic content) in your template.  If you do, create the variables by putting $ around the name (ie $Value$). 
    5. Determine if you want your variable to use a macro.  If so, choose one fro the list on the right.

      TemplateCreator
  5. Time to use your new LiveTemplate
    Go back to your coding window and type in the shortcut you gave your template (ie ateq) and watch as code is generated.

There you go, 5 simple steps to creating and using a LiveTemplate.  You should not be much more productive and be able to code circles around your fellow developers.

Till next time,

[----- Remember to check out DimeCasts.Net -----]



Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# June 18, 2008 12:11 PM

sergiopereira said:

I was happy to notice that one of the macros returns one of the other variables with the first character in lower case (I miss that in the VS snippets)... On the other hand, I wish this was a little more scriptable, something easier than a full-blown VS macro but with some more smarts. I love the kind of templates I can add to TextMate for example.

# June 18, 2008 12:22 PM

David said:

Great summary. I just wanted to add that you can use $END$ to indicate where you want the cursor positioned after filling the live template. This can be really helpful:

[Test]

public void $ShouldDoSomething$() {

 $END$

}

# June 18, 2008 7:56 PM

Dew Droplet - June 19, 2008 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Droplet - June 19, 2008 | Alvin Ashcraft's Morning Dew

# June 19, 2008 8:52 AM

Andrei Butnaru's blog said:

Productivity tools, Resharper

# July 21, 2008 3:52 PM

Barmeister com drink recipe italian valium. said:

Valium.

# July 26, 2008 11:34 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Proudly Partnered With


This Blog

Syndication

News