Reader small image

You're reading from  TextMate How-To

Product typeBook
Published inOct 2012
Reading LevelIntermediate
PublisherPackt
ISBN-139781849693981
Edition1st Edition
Languages
Right arrow
Author (1)
Christopher J Mears
Christopher J Mears
author image
Christopher J Mears

Chris Mears lives in San Francisco and is the lead web developer at Canned Banners, a startup he co-founded. Though he considers himself a generalist when it comes to technology, he finds true passion developing for the Web. When he's not thinking and dreaming about code, he enjoys going to concerts, practicing on his guitar, homebrewing beer, and tea snobbery. This is his first book.
Read more about Christopher J Mears

Right arrow

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.

Previous PageNext Page
You have been reading a chapter from
TextMate How-To
Published in: Oct 2012Publisher: PacktISBN-13: 9781849693981
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Christopher J Mears

Chris Mears lives in San Francisco and is the lead web developer at Canned Banners, a startup he co-founded. Though he considers himself a generalist when it comes to technology, he finds true passion developing for the Web. When he's not thinking and dreaming about code, he enjoys going to concerts, practicing on his guitar, homebrewing beer, and tea snobbery. This is his first book.
Read more about Christopher J Mears