Book Image

TextMate How-To

By : Chris Mears, Christopher J Mears
Book Image

TextMate How-To

By: Chris Mears, Christopher J Mears

Overview of this book

Not all text editors are created equal. TextMate was created with versatility and power to the developer. Whether you want to organize your files in projects, utilize the efficiency of code completion, take advantage of the thousands of publicly available bundles, or gain insight using powerful regular expression searching, TextMate is an essential and easy-to-use tool you need in your development arsenal. "TextMate How-To" is a practical guide filled with conventional recipes on using one of the most popular text editors on the OS X platform. It is a great resource for anyone who wants to learn how to code more efficiently and effectively, no matter what programming or scripting language you use. This book will guide the reader through using TextMate for practical purposes. It will start with configuring the application, then cover navigation and editing of files, and finish with bundles and advanced features. Throughout the book, the reader will quickly master the key features of the application through easy to follow tasks. Using this book, the reader will learn the most common text editing and coding tasks including navigation through the document and searching of text. The reader will then learn about working with and navigating between files and projects as well as utilizing bundles to greatly speed up development. Finally, explore the ability to use shell commands and macros to increase productivity. With just a few hours, "TextMate How-To" will teach the reader everything necessary to hit the ground running with this powerful text editor.
Table of Contents (7 chapters)

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...

  1. 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:

  2. 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:

  3. 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:

  1. Open a file (Command + O).

  2. Select the Show Hidden Files checkbox as shown in the following screenshot:

  3. Navigate to your Home folder, then Library/Application Support/TextMate/Bundles, then select the bundle name and click on Open, as shown in the following screenshot:

  4. 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).