Using macros (Should know)
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.
How to do it...
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:
How it works...
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).
Temporary macros
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.
Note
Your temporary macro will be lost if you record another macro or close TextMate.
There's more...
Editing your macro requires a little bit of XML knowledge, but it is easily done using TextMate to open the bundle source files.
Editing macros
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
Home
folder, thenLibrary/Application Support/TextMate/Bundles
, then select the bundle name and click on Open, as shown in the following screenshot:The
.tmbundle
file 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).