by Chad
12. April 2010 10:43
Last week I found my new favorite Visual Studio 2008 productivity tool: TemporaryMacro. You can find this functionality in Tools > Macros > Record/Run TemporaryMacro. Being a shortcut-junkie though, I prefer Ctrl+Shift+R and Ctrl+Shift+P for recording and playing respectively.
The Macro feature in Visual Studio is one of those things that I’ve always been aware of, but have never really taken advantage of because I didn’t want to manage a library of macros. The TemporaryMacro feature is a quick and easy to use “throw away” macro and great for tedious text modifications.
Example Usage
This is a simple example, but yesterday I had pasted a digital certificate thumbprint into a .config file. The thumbprint had a space every two characters, that wasn’t necessary. To remove the spaces, I had to press: Right > Right > Delete for all 19 spaces that I wanted to remove.
With macros I started the recorder by pressing Ctrl+Shift+R. I pressed Right > Right > Delete to remove the first space. I then pressed Ctrl+Shift+R to stop the macro recording. Then I quickly pressed Ctrl+Shift+P 18 more times to replay the macro removing the remaining spaces.
Useful Text Manipulation Shortcuts
The record > replay process takes a tiny bit of forethought because you need to consider how executing the macro repeatedly will behave. You also need to think about the edge case of your final replay as you may accidentally change text that you didn’t intend to change. I use these shortcuts all of the time, but I find that within the context of macros I use them differently to affect the behavior of the text manipulation replays.
Arrow – Move the cursor left or right one character or up or down one line.
Shift+Arrow – Select text while moving cursor moves up, down, left, or right.
Ctrl+Left (or Right) – Move the cursor left or right one word at a time.
Shift+Ctrl+Left (or Right) – Select text while moving left or right one word at a time.
End – Move the cursor to the end of the line.
Ctrl+End – Move the cursor to the end of the file.
Home – Move the cursor to the beginning of text for the current line.
Home (a second time) – Move the cursor to the begging of the line.
Shift+{any of the home/end combinations} – Select text while moving the cursor.
Ctrl+Home – Move the cursor to the beginning of the file.
Shift+Delete – Delete the entire line.
It may feel slow at first, but I promise you that if you stick with it, the TemporaryMacro will become a frequent tool in your daily coding habits.