Zap Documentation      Latest release     
ZapRedraw      Contact      Download     

Previous | Contents | Index | Next

Chapter 8: Searching

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.

8.1 Search options

A number of options control how Zap's search system works. These are: raw search, case sensitivity, macros, \-commands and to window.

8.1.1 Raw search

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.

8.1.2 Case sensitivity

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.

8.1.3 Macros

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:

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.

8.1.4 To window searching

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.

8.2 \-commands

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:


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.

8.3 Replace

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.

8.3.1 Global replace

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:

8.3.2 The replace expression

The format of the replace expression is as for the search string, with the following additions:


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.

8.4 Incremental search

(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

© Copyright Zap Developers 1992-2004. All Rights Reserved.