This is a draft of the TextMate 2 manual
The primary search actions which you should learn the key equivalents for are:
- Edit → Find → Find Next (⌘G)
- Edit → Find → Find Previous (⇧⌘G)
- Edit → Find → Show History (⌃⌥⌘F)
- Edit → Find → Use Selection for Find (⌘E)
Another action is Bundles → Text → Selecting → Extend Selection to Include Next (⌃W), more detail about this action can be found in the search clipboard section below.
TextMate’s search dialog can be brought up by selecting Edit → Find → Find… (⌘F). Once this dialog is showing the Edit → Find → Find All (⌥⌘F) menu item will trigger the
Find All button in the search dialog and show you all results from the current document. When the search dialog is not showing, the same action will instead select all matches in the current document.
If you wish to search for tab or newline characters then you can press option-tab or option-return to insert these in the search or replace fields. The fields will automatically grow with their content.
The sigma button (
Σ) in the search dialog can be used to count the number of results in the current document. An alternative is to use the
Find All button, as this will also reprot the total number of matches.
You can select Edit → Find → Find in Project… (⇧⌘F) to bring up the search dialog with the
In pop-up defaulting to the current project folder. You can also click the magnifying glass in the file browser to open a search dialog, though this will default to search the selected items in the file browser, or the folder shown in file browser, when there is no selection. This same behavior can also be triggered by pressing ⇧⌘F while focus is in the file browser.
Should you wish to extend the search to a parent folder then you can use File Browser → Enclosing Folder (⌘↑) or interact with the
In pop-up menu.
In pop-up is showing a folder you can select
Find All to perform a search across the files in the selected folder.
If you wish to limit the search then you can edit the
matching glob string. For example to only search HTML files you can make it
*.html or if you wish to exclude all files in the
vendor folder, make it
See filtering files for more options.
If you wish the search to follow symbolic links then you should enable this via the gear pop-up menu to the right of the
matching text field.
You can abort a running search by clicking the stop button that appear to the left of the status text, closing the window, or pressing ⌘..
TODO Syntax highlight in search fields
After a folder search you will see the results grouped by file. There are a few useful actions related to these results which we’ll go over in this section.
Using command ⌘1-⌘n will select the first result in the n’th file. It will also move focus to the results list, allowing you to use arrow up and down to move through the results.
Using Edit → Find → Find Next (⌘G) will select the first result, and subsequent uses will advance through the results. Likewise Edit → Find → Find Previous (⇧⌘G) will initially select the last result and move backwards through the results.
If you close the search dialog and use Edit → Find → Find Next (⌘G) in a document with no more results, TextMate will open the next file which have results and select the first result in this file.
From the gear menu in the find dialog you can select Collapse Results (⌥⌘1). This is useful when you are only interested in which files contain matches and not the matches themselves.
Also in the gear menu are actions for copying the results to the clipboard. You can copy just the matching parts or the entire line with the match, either with or without file name. The first option, copying matching parts, is useful for regular expression searches, for example a project search for
href=".*?" followed by Copy Matching Parts will provide you with a list of all links across all files. You can paste that into a new document and use Bundles → Text → Sorting → Sort Documents & Remove Duplicates (F5) to remove duplicates.
When you search for regular expressions the replacement string is interpreted as a format string where you can use captures from the search. Here is a blog post about using captures and nested replacements in TextMate.
As mentioned in the blog post, TextMate offers you replacement previews. These are automatically shown when focus is in the
Replace text field.
For results that you do not wish to have replaced, uncheck the check box next to the result. By holding down option (⌥) when clicking a check box, all results for the corresponding file will be excluded or included.
Similar to how you can copy text to the clipboard with Edit → Copy (⌘C) and paste it later with Edit → Paste (⌘V) you can use Edit → Find → Use Selection for Find (⌘E) to place the current selection on the (globally shared) search clipboard and use Edit → Find → Find Next (⌘G) or Edit → Find → Find Previous (⇧⌘G) to find the next or previous occurrence of the search string.
The content of the search clipboard is also used when opening the find dialog using Edit → Find → Find… (⌘F).
TextMate maintains a history of your previous search strings and you can select Edit → Find → Show History (⌃⌥⌘F) to see previous search strings. If you close the list with return (↩) then TextMate will search for the next occurrence of the selected string, whereas closing the list with escape (⎋) will change the current string on the search clipboard but not perform a search.
In addition to placing selection on the search clipboard, you can also use Edit → Find → Use Selection for Replace (⇧⌘E). This is useful if you want to perform a replacement and bypass the search dialog. The steps would be:
- Select the string you wish to replace and press ⌘E.
- Overtype the selection with the replacement, select it, and press ⇧⌘E.
After this you can use Edit → Find → Replace All (⌃⌘G), make a selection and use Edit → Find → Replace All in Selection (⌃⇧⌘G), or possibly Edit → Find → Replace and Find (⌥⌘G)
If you wish to replace only a few instances near the caret, it might be easier to select the first match and then use Bundles → Text → Selecting → Extend Selection to Include Next (⌃W). This action will make the next occurrence of the currently selected string part of the selection, causing multiple occurrences to be selected. Use it to select all the occurrences you wish to replace, and then perform your replacement, as the changes you do to the first occurrence will be mirrored to all the other occurrences.
With no selection the action is Edit → Select → Word (⌃W) which means that for single word replacements you only need to place the caret on the word to be replaced and then press ⌃W until all the occurrences are selected.
Four options affect how the search works, these can be toggled either via the Edit menu or in the find dialog.
The options are as follows:
|Ignore Case||⌥⌘C||Perform a case insensitive search.|
|Regular Expression||⌥⌘R||Treat the search string as a regular expression.|
|Ignore Whitespace||Whitespace in the document and search string is ignored. This makes it easy to search for multi-line content regardless of its indentation.|
|Wrap Around||⌥⌘A||Start over from the top of the document when no match is found.|
Selecting Edit → Find → Incremental Search (⌃S) will open a search field at the bottom of the window where a search string can be entered, and TextMate will show what it matches in the document. The search is case-insensitive and ignores whitespace.
While the search field is showing you can use the following key equivalents:
|⌃S ⇥||Find next|
|⌃⇧S ⇧⇥||Find previous|
|↩ ⎋||Close search field|