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)

Finding and replacing text (Must know)

This task will show you how to find text in the document using a string or a regular expression, as well as replace the text you find.

How to do it...

The different Find options are explained as follows:

  • The Find option will search for any occurrence of a specified string. From the menu, select Edit | Find | Find… (Command + F). For finding a normal string, uncheck the Regular expression checkbox:

  • The Find option with the Regular expression checkbox checked will search for any occurrence using regular expressions. To do this, select Edit | Find | Find...:

  • The Find Next option will search for the next occurrence. From the menu, select Edit | Find | Find Next (Command + G).

  • The Find Previous option will search for the previous occurrence. From the menu, select Edit | Find | Find Previous (Command + Shift + G).

  • The Use Selection for Find option will search for the selected text. From the menu, select Edit | Find | Use Selection for Find (Command + E).

  • The Replace text functionality is included in the Find dialog box (select Edit | Find | Find… or Command + F). You can use Replace, Replace All, or Replace & Find, which are described in more detail in the How it works… section.

How it works...

The Find dialog box has some very helpful options. These are as follows:

  • Ignore case will perform a find irrespective of case.

  • Replace will replace the currently selected find occurrence.

  • Replace All will replace all find occurrences in the document.

  • Replace & Find is useful to test out your find occurrences before using Replace All and is also useful when you're not quite certain if you want to replace everything.

  • The button will output the number of occurrences of the find string or regular expression. This is helpful to do before a full replacement. Also, you can gauge the extent of the upcoming changes and make edits to your find text, if needed.

There's more...

There are some extended features of the find functionality that are useful if you do a lot of searching or if you need to find and/or replace multiple lines.

Find and Replace history

In case you want to repeat a past Find and Replace search, there's a history drop-down you can use by clicking on the downward-facing triangle next to the input boxes.

Expanded Find and Replace

If you need some more room to fully view your Find and Replace strings or regular expressions, you can click on the downward-facing triangle underneath the Σ button:

Also, if you need to insert a literal tab or return, hold down the Option key while pressing Tab or return.