Macros make it easy to record several actions or keystrokes and then replay them multiple times. This task will provide an overview of how to record and subsequently execute macros in your document.
You can start (and stop) a macro recording by using the keyboard shortcut Command + Option + M (or select Bundles | Macro | Start Recording/Stop Macro). Once enabled, you will notice a red recording dot in the bottom-right corner of the document window, as shown in the following screenshot:
Once you've stopped recording (Option + Command + M), you can save the macro by using the keyboard shortcut Control + Command + M (or select Bundles | Macro | Save Last Recording), which will open the Bundle Editor window. Enter a name for the macro and choose an activation method of either a keyboard shortcut or tab trigger, as shown in the following screenshot:
Once named and set up with an activation method, you can use your newly created macro! The following screenshot shows a macro being used in PHP:
Macros are best used for keystrokes that you keep repeating. In the previous example, I made a macro out of a common pattern I use in PHP development (WordPress, CakePHP, and so on) to print out a string, which typically includes a variable (for example, for debugging purposes).
If you just want to use your macro without saving it long-term, you can use the previously recorded macro by hitting the keyboard shortcut Shift + Command + M, or from the menu by selecting Bundles | Macros | Replay Last Recording.
Editing your macro requires a little bit of XML knowledge, but it is easily done using TextMate to open the bundle source files.
Sometimes it can be difficult to record a macro perfectly the first time. The bad news is that TextMate doesn't currently support editing macros. The good news is that if you're comfortable with XML, you can edit the
.plist file by opening it in TextMate. The steps for editing macros are as follows:
Open a file (Command + O).
Select the Show Hidden Files checkbox as shown in the following screenshot:
Navigate to your
Library/Application Support/TextMate/Bundles, then select the bundle name and click on Open, as shown in the following screenshot:
.tmbundlefile will open as a project. You will find your macros in the Macros folder, as shown in the following screenshot:
Once you edit your bundle, don't forget to select the Reload Bundles option (select Bundles | Bundle Editor | Reload Bundles).