SadullahCeran
SadullahCeran

Reputation: 2435

Resharper - VisualStudio 2012 Custom Shortcut to Replace Selection

In the web project I have been working on, we have string literals all over like

<div class="title">This is Title</div>
<div class="text">This is some text<div>

In order to make the application multilingual, I need to replace all these literals to some helper methods:

<div class="title">@TranslationHelper.Translate("This is Title")</div>
<div class="text">@TranslationHelper.Translate("This is some text")<div>

I want to create a custom shortcut (e.g CTRL + ALT + M) either through Resharper 8.0 or Visual Studio 2012.

When I select the text I want to transform and press the shortcut I defined, Visual studio should replace the selection with the format I defined.

How do I do that?

Upvotes: 1

Views: 180

Answers (1)

wal
wal

Reputation: 17719

You can use Resharpers Surround With feature to acheive this. First open the Template Explorer

Resharper -> Template Explorer

then click New Template:

enter image description here

Enter your desired string in the template editor and save (Ctrl-S)

enter image description here

Now place your cursor in the desired text. On another note you can use Resharpers Extend Selection feature to quickly select the text (Shortcut is Ctrl-Alt-RightArrow)

Once the text is selected choose press Ctrl-E,U (Resharper Surround with)

enter image description here

Click More where you can select your new template and ensure you add it to the quicklist so its added to the list for next time

enter image description here

enter image description here

Upvotes: 2

Related Questions