Previous | Contents | Index | Next
Zap's search system is quite powerful, and is based loosely on UNIX regular expression searching (as used, for instance, in Emacs. There are a variety of ways in which you can use it; the main ones are search to cursor, search to window, replace, and incremental (or keyboard) search. These are started by the F4
and F7
keys, by sF4
, and by cS
/cR
(for forward/backward incremental search), respectively. The first three use similar dialogue boxes. The first two are essentially the same, with one important difference: search to cursor will jump the cursor to the search match, while search to window creates a throwback buffer containing all the matches (search to window is also sometimes called search to buffer). See section 10.7 for more information about throwback buffers.
The Zap search window is split into several sections. In the first column is a set of search options; the second column gives the direction (forward, backward, forward from the start of the file, or all files starting from the start of the first one); and the final column gives some more options. Below these columns are the search expression (and, for the replace dialogue box, the replace expression) and a button labelled Edit macros
which we'll cover later. In addition there are the expected Cancel
and Find
buttons, and a button marked couNt
with a field below it - clicking this (or pressing cN
, which is why the label is capitalised the way it is) will fill the field with the number of matches of the current search string.
cP
inserts the current selection in Zap into whichever search/replace field has the caret. cK
clears the history; Page up
and Page down
and the cursor keys navigate the history (cursor keys will move from field to field in the replace dialogue), and cTab
replaces the entry with the one used in the last search.
A number of options control how Zap's search system works. These are: raw search, case sensitivity, macros, \-commands and to window.
If this option is turned on, then the whole file will be treated as a single line of text and searched accordingly. Thus \<
will match the start of the file, and \>
the end of the file (see section 8.2 below). The reason it's called 'raw search' is that in this mode, Zap won't 'detokenise' first - so you're searching the raw data of the file. With this option turned off, the search is done line by line, but BASIC mode will detokenise the lines (so you are searching against what you see when Zap displays the file, rather than against what is stored); Code mode disassembles, and so on.
If this option is turned on, strings of letters will only match if their case agrees; if off, matching ignores case. Case matching is currently only done for letters in ASCII - ie the letters A-Z. Accented characters in ISO Latin 1 are not understood for case insensitive matching.
To make your life easier, you can define up to sixteen macros. These are substituted in the search string before the search is actually performed. Macros may expand to anything - most usefully, they may contain \-commands, as defined below.
There are three default macros:
*
expands to \.\*
(matches anything).#
expands to \ #
(matches any character).\d
expands to \[0-9]
(matches any digit).The 'Edit macros' button in the search windows allows you to view and edit these macros; note, however, that to change them permanently you'll have to edit Zap's textual settings file. See section 12.3.1 for more information.
This option is automatically turned off when you press F4
, and turned on when you press F7
. When it is turned off, the cursor will be moved to the first match, and subsequent matches may be got by pressing sF7
(next match) and scF7
(previous match). A beep will sound if there are no more matches, and the cursor will not move.
If it is turned on, all matches are placed in a new throwback file. Double clicking entries in this file will cause the cursor to jump to the corresponding match - see section 10.7 for more information.
The search dialogues have a switch to turn off \-commands. If you don't, then the character '\' introduces a wildcard. The wildcards are documented below, and are also summarised in the search windows (although they are initially hidden - click the toggle size icon to reveal the wildcard descriptions).
In this list, x
stands for any ASCII character unless otherwise mentioned:
\x
- Matches x
case sensitively (irrespective of the case sensitivity option), unless \x is mentioned below.`x
- Matches x
only (without any replacement of macros).\(, \)
- Act as brackets for nesting expressions.\{, \}
- Act as brackets, but may be referred to in the replace string (see section 8.3 below).\#
- Matches any character. eg: a\#d
matches and
, aid
and aad
, but not ad
.\.
- Matches any character except the return character.\*
- Matches any number (including zero) of the previous expression. eg: fo\*
matches f
, fo
, foo
etc., and \(and\)\*
matches the empty string, and
, andand
, etc.\%
- Matches as many as possible of the previous expression. Thus \[0-9]\%
matches 1
in 1pt
, and the 395
in ab395rty
.\|
- Matches either one expression or another. eg: hello\|goodbye\|fred
matches hello
, goodbye
or fred
. \(a\|b\)\*
matches abababa
, abbba
, etc.\[...]
- Matches a range of characters. eg \[a-zA-Z%]
matches any letter or a %
. If a ^
if given immediately after the opening bracket, then the range given is the characters that the expression won't match, so \[^abc]
matches any character except a
, b
or c
. A ]
may be included in the range by placing it first in the list (after the [
opening the list, or after the ^
if present).\<
- Matches the null string at the start of a line.\>
- Matches the null string at the end of a line. Note that this doesn't work properly; phip\>
won't match phip
at the end of a line. Assuming your return character is the normal one, phip\n\>
will do the trick (this will be fixed at some point).\+
- Turns on case sensitivity for the following letters. Its effect stops at the next wildcard, bracket or command. It doesn't affect nested or bracketed statements. eg: \+Fred\|Bill
will match Fred
case sensitively, but not Bill
.\-
- As above, but turns off case sensitivity.\\
- Matches a \
.\ddd
- Where d is any decimal digit, matches a byte of that value, eg: \0alf
matches the byte 0 followed by alf
, and \233
matches the byte 233. Please note that \999
matches byte 99 followed by 9
, since 999 > 255 (the greatest possible value of a byte).\&hh
- As above, but matches the hex byte hh when h are valid hex characters.\A
- \Z
- Matches control A to control Z.\a
- Matches alert (ASCII 7).\b
- Matches backspace (ASCII 8).\f
- Matches a form feed (ASCII 12).\hdd..
- Where d's are hex digits, match the given word (32 bit number).\n
- Matches a newline (ASCII 10).\o
- Matches any character except a .
(useful for matching filenames).\r
- Matches a return (ASCII 13).\t
- Matches a tab (ASCII 9).\v
- Matches a vertical tab (ASCII 11).\?
- Matches a delete (ASCII 127).\wdd
- Where d's are decimal digits, match the given word (32 bit number).\xhh
- Matches hex numbers as above (where x
is the letter x
, eg: \x2D
).Examples:
cat\|mat
matches cat or mat.re*ment
matches any occurrence of re
then ment
on a line.SWI
matches any SWI (in code mode).LDR\|STR
matches any load or store instruction.R6
matches any instruction using R6
.BL*&0000A95C
matches any call to &0000A95C
.\&0A
matches the byte &0A.\<fred
matches fred, but only at the start of a line.main`(
matches main(
.\d\%
matches any decimal number (where \d
is a macro which expands to \[0-9]
).The search will be much faster if you give a definite first character to start with. eg: a\(nd\|pple\)
will be a lot faster than and\|apple
. If the search takes longer than a third of a second, then an hourglass will come up displaying the position in the file as a percentage underneath. You may stop the search by pressing Escape
, and the partial results will be displayed if you are using Search to window
.
Pressing sF4
brings up the search and replace dialogue box. The first two columns of this are the same as for the search dialogue; the last one has a global
option instead of to window
. couNt
works the same way as for searching (it does not perform any replaces), as does Edit macros
.
With the global option turned on, replace will replace all occurrences of the search expression with the replace expression, in the direction of the search. (So if you're searching forwards, only matches forwards of the cursor will be replaced; if the search direction is all files
then all matches in all files will be replaced.)
With global turned off, each match will be highlighted in turn, and a Replace ?
window will appear with a series of options. As usual, you can press control and the first capitalised letter of each button to get the desired action; in this case you can also do the same without holding down control. The options are:
Replace
- Replaces that match and moves to the next.Skip
- Doesn't replace this match, and moves to the next.Last
- Replaces this match and aborts the operation.Undo
- Undoes the last replace operation.reDo
- Redoes the last replace operation.All
- Replaces all matches from the current match onwards.Front
- Brings the window containing the match to the front; particularly useful when you are replacing across all files.In sel
- Replaces all matches in the selection (since the replace system selects the word it's considering, you'll have to make your own selection while the operation is in progress for this to be useful).Cancel
- Closes the window and aborts the search/replace operation.The format of the replace expression is as for the search string, with the following additions:
&n
- Replace with the n'th \{ ... \}
expression in the search string. n starts at 1 and must be less than 10.&&
- Replace with an &
.Examples:
cat
, R: (the empty string) removes all occurrences of cat
.\{cat\}
, R:&1s
replaces cat
with cats
, preserving case.time=\{\#\*\}
, R:time is &1
replaces time=58
with time is 58
etc.To convert spaces between columns of figures in a table into tab characters, use \{\d\} \*
as the search string, and &1\9
as the replace string. Alternatively, replace \{\d\} \%
with &1\9
.
(This is also sometimes called keyboard or interactive search, or i-search.)
Incremental search is activated by pressing cS
(to search forward) or cR
(to search backwards - reverse incremental search). When you do this, a minibuffer will be opened for you to type the search string into. As you type the string, Zap will search though the text placing the cursor at the end of the next match. If there is no match, Zap will beep and display (fail)
. Pressing Delete
removes characters from the search string; doing so will move you back to the first successful match of whatever is left in the search string.
To halt the search at the current position, press Escape
or Return
. If you press an arrow or function key, then the search will be halted and the keypress acted upon. Alternatively, cG
(CANCEL
) will cause the search to be cancelled and the search returned to its initial position before the search.
Pressing cS
or cR
whilst in search mode will move you to the next/previous match; if the search string was empty then the previous search string will be placed in the buffer.
Macros are turned off during the search; however \(
and all other \-commands will still work. The current settings of the options in the search window will be used (so you if you have disabled slash-commands in searches, they won't work in incremental search either).
The next section in the manual is chapter 9, which covers various advanced features of Zap, as well as Zap's internal help system.
Alternatively, you could move on to chapter 10, which explains Zap's different editing/displaying modes, and looks at some of the most useful ones. Modes form the key to many of Zap's most useful features, and since they've been occasionally mentioned in the manual up till now you probably want to learn more about them.
Previous | Contents | Index | Next