Searching a file
In the text viewer, find text or bytes, narrow a long file to the lines that match, or go straight to a line. Trees, tables, diffs and notebooks have searches of their own, on the same key.
At a glance
| Key | Action |
|---|---|
| F7 | Search… |
| F3 | Find next |
| ⇧F3 | Find the one before |
| F6 | Only the lines that match |
| ⌘S | Save the lines shown… |
| ⌘G | Go to… |
Finding text
F7, or ⌘F, asks what to look for, and Enter finds it. The match is marked in yellow, and brought to the top of the screen if it was not already on it. F3 and ⇧F3 look again without asking.
- Find
- What to look for. Earlier searches are in its list — the same list as every search in a file, in the editor too.
- Match case
- Capitals and small letters differ. Off, they match each other.
- Regular expression
- The pattern is a regular expression rather than the text itself.
- Match across line ends
- For a regular expression only: a match may run on past the end of a line.
- Bytes in hex, like 4D 5A
- While the bytes are shown — see finding bytes.
- Find next, Find previous
- Which way to look, from the top of the screen. Enter is Find next.
A pattern that cannot be used grays the buttons, and says why under the field.
- F3 goes on from the last match. It is gray on the key bar until you have searched in this file.
- The search stops at the end of the file, or at its start, and the header says not found. It does not go round.
- A pattern that takes too long is given up on, and the header says the pattern took too long.
- With a filter on, only the lines the filter kept are searched.
Finding bytes
While the bytes are shown, the dialog also has Bytes in hex, like 4D 5A. Ticked, the pattern is bytes, however it was written down:
4D 5A,4d5aand0x4D 0x5Aare the same two bytes; spaces, commas, dashes and colons are left out.- It needs an even number of digits, two to a byte.
- Case and regular expressions mean nothing to bytes, so those boxes are gray.
What is found is marked twice: in the hex, and in the characters beside it. Unticked, the search looks for text, as it does in the text.
Showing only the lines that match
F6 asks for a pattern and shows only the lines that match, which turns a long log into the part of it you were looking for. The same key shows the whole file again, from where you are.
- Keep lines matching
- The pattern. Its list of earlier patterns is its own.
- Match case, Regular expression
- As when finding text.
- Whole line only
- The pattern must match the whole line, not part of it.
- Show what does not match
- Keeps every line that does not match — the way to take the noise out of a log.
- Lines of context either side
- Up to 99 lines around each match, shown dimmer.
In the lines it keeps:
- ↑ and ↓ move the marker from match to match, past the lines around them. Home and End go to the first and the last.
- Enter goes to the marked line in the whole file, and takes the filter off. So does the filter’s own key: either way the marked line is at the top.
- A
…stands for lines left out. Numbers, in the header and down the side, are the file’s own. - The header says how many lines matched. It keeps at most 200,000 lines, or 8 MB of them; past that it says first 200,000 matching.
- Asked again, the dialog starts from the last filter.
Changing the encoding takes the filter off. Showing the bytes puts it aside, until you come back to the text.
Copying and saving the lines it kept
With a filter on, ⌘C copies every line shown, and the header says how many. ⌘S (⌘S) asks where to write them in a Save as dialog, and asks again before replacing a file.
- Include 2 lines either side of each match
- Adds the lines around each match to the file, as many as the filter’s own Lines of context, or two where it has none. Unticked, the file holds the matching lines alone.
If the file was longer than the filter could read, only the lines it kept are copied or saved, and the header says so.
Going to a line
⌘G asks where to go:
| Showing | Type | For example |
|---|---|---|
| Text | A line number, counted from 1 | 1204 |
| Text or bytes | How far through the file, as a percentage | 50% |
| Bytes | An offset in hex, as the offset column shows it | 1F40 or 0x1F40 |
| A table | A row number, as the left margin shows it | 120 |
- A percentage is a whole number, up to 100.
- A percentage or an offset is there at once, however big the file.
- A line the viewer has not counted to yet is not refused: the header says going to a line… until it gets there.