Dec 062016
 
 December 6, 2016  Posted by at 3:03 pm Visual Studio  Add comments

I was asked for a simple example showing how to use/get started with the Macros for Visual Studio extension I mentioned a efw days ago on Twitter. Here is a simple ‘get-started’ I threw together today. I’ll expand this post later with a better example, as well as a video.

The extension can be download here

Some of the features:

  • Record and playback active document operations and Visual Studio IDE commands
  • Playback multiple times
  • Manage and persist macros with a Macro Explorer
  • Assign keyboard bindings to any macro
  • Macro editing in Visual Studio with DTE IntelliSense
  • Sample macros

Once installed the extension can be foun in the Tools menu, and there is also a window you can choose to add to your workspace (Macro explorer).

2016-12-07_16-59-22

A macro I made for fun is one that converts camel case properties to pascal case. This is very handy if you use the feature I discussed in the previous post and don’t have Resharper (the feature I’m talking about is the paste JSON as classes feature in Visual Studio). I’m sure somebody is going to tell me that this is already integrated in Visual Studio somehow 😀

Step by step

On the property public int last_edit_date { get; set; } I leave the cursor at the last bracket and start recording a macro (Ctrl + M, R)

public int last_edit_date { get; set; }

I use Ctrl + [ to move the cursor to the first bracket, then Ctrl + Left to get to the beginning of the property name.

public int last_edit_date { get; set;}

I hold down Shift and move right on column, highlighting the first letter of the property name.

public int last_edit_date { get; set;}

I enter Ctrl + Shift, U which upper cases that letter.

public int Last_edit_date { get; set;}

Then, to let the macro continue on to the next property I move the cursor down with Down arrow, and then Ctrl + End to get to the first bracket.

I then end recording with Ctrl + M, R (same as start recording). If you save the macro it would look like this:

dte.js =>

      dte.ExecuteCommand(“Edit.GotoBrace”);

      dte.ActiveDocument.Selection.WordLeft();

      dte.ActiveDocument.Selection.CharRight(true);

      dte.ActiveDocument.Selection.ChangeCase(2);

      dte.ActiveDocument.Selection.LineDown();

      dte.ActiveDocument.Selection.EndOfLine();

The default path for the macros file is:

C:\Users\{USER}\AppData\Local\Microsoft\VisualStudio\14.0\Macros\dte.js

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

What is 12 + 5 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)