MAINEDIT User's Guide, Chapter 4

previous   next   top   contents   index   framed top   this page unframed


4. Searching

The T command is the text search command (if you don't like thinking of T as standing for “Text search”, think of it as “Try to find”). It prompts for the search string, then moves the cursor to the first occurrence of the search string, if found. Table 4–1 lists the basic search commands. In the table, s represents the search string that you type in response to the prompt.

Table 4–1. Text Search Commands
Command Search right and:
Ts<eol> all lines down for s
nTs<eol> n-1 lines down for s (n required)
.Ts<eol> all lines down for identifier s
n.Ts<eol> n-1 lines down for identifier s (n required)
$Ts<eol> all lines down for s, case-sensitive
n$Ts<eol> n-1 lines down for s (n required), case-sensitive
.$Ts<eol> all lines down for identifier s, case-sensitive
n.$Ts<eol n-1 lines down for identifier s (n required), case-sensitive
!Ts<eol> pattern search for s all lines down
!nTs<eol> pattern search for s n-1 lines down
$!Ts<eol> pattern search for s, case-sensitive
n$!Ts<eol> pattern search for s, n-1 lines down, case-sensitive
?!T display help for pattern searches

4.1. Case-Sensitive Search

The $ modifier causes a search to be case-sensitive. The case of the string searched for must match the given string exactly. For example, $Txyz<eol> finds lowercase xyz, but does not find uppercase XYZ or mixed-case Xyz. In the absence of the $ modifier, searches are case-insensitive, so that Txyz<eol> matches xyz, XYZ, or Xyz.

4.2. Identifier Search

The T command searches for any sequence of characters that matches the target string, even if it occurs in the midst of a word. .T, however, searches for an “identifier”; i.e., the target cannot be bordered by an alphanumeric character. For example, target string “at” specified to the T command is found in match, Attach, watch, or any other string containing the consecutive letters “at” in any upper-lower case mixture. The .T command, on the other hand, does not find the target “at” in any of these words, but does find it in “. At”, “at;”, or “AT?”. Tabs in the search string match target tabs, while blanks in the search string match both tabs and blanks.

Use the - modifier to search left and towards the beginning of the file. Use the Q modifier to specify multiple target strings, separating the targets with <eol>. Terminate the last target with an extra <eol>. The search then finds the first occurrence of any of the target strings.

Use the + modifier to wrap around the beginning or end of buffer during the search. The + and - qualifiers can be used in the same search command. The + modifier is useful when you want to find the target string anywhere in the file regardless of the current location. If this modifier is not used, the search is terminated by the beginning or end of the buffer.

4.3. Pattern Search

The ! variant of the T command provides regular expression pattern searches. The . and Q modifiers are not allowed in combination with !.

T with no ! is generally faster but far less flexible than !T.

The command ?!T writes a description of the characters allowed in patterns to CMDLOG. You will probably want to consult this description before using the command, as the list of pattern matching characters is subject to change. Some of the more commonly used characters include:

Char Meaning
x represents itself, where x is an alphabetic char, a digit, period, or space. All other chars are special and must be quoted with \ to represent themselves.
( and ) for grouping a sequence of chars
| either previous or following group or char
' 0 or more of following group or char
` 1 or more of following group or char
? any char except bof and eof
* 0 or more of any char (same as ('?))
$ eol (end-of-line)
& any alphabetic char (A|B|C|...|X|Y|Z|a|b|c|...|x|y|z)
# any digit (same as (-09))
! any alphabetic char or digit (same as (&|#))
~X any char not matching the pattern X (may need to parenthesize X)
< bof (beginning-of-file)
> eof (end-of-file)
@ blank, tab, eol, bof, eof (same as ( |;|$|<|>))
= no character; e.g., can represent 0 or 1 x's as (x|=)

For example, to look for the strings “this red shoe.” or “these red shoes.”, regardless of how many whitespace characters occur between the words of the phrase, use the search pattern:

(this|these)`@red`@shoe(s|=).

4.4. Line Search

The QQ qualifier causes each target line to be displayed on the message row, preceded by a page and line number. This is called a line search. MAINED waits for a one-character response:

Upper and lower case distinctions are ignored in the search and target strings. If MAINED does not find some target FOO, the cursor is not moved, and MAINED beeps and gives the message:

Did not find "FOO"

The prompt for the search string gives as the default the string(s) last searched for. Type just <eol> to use the default:

Search string ("FOO"): <eol>     (search for FOO)

4.5. RS: Recall SearchStrings into Buffer

Sometimes you want to edit search strings with normal editor commands. You can do this by inserting the current search strings into the current buffer with the RS command, editing them, and then turning them back into search strings with the +R commands, as described below.

The RS command inserts the current search strings above the current line, one per line. The search strings are uppercase.

Example: if you have just issued the command Tabc<eol> to search for abc, then RS inserts the string ABC on a new line above the current line.

Example: if you have just issued the command QTabc<eol>def<eol>ghi<eol><eol>, then the RS command inserts three lines above the current line and sets the first to ABC, the second to DEF, and the third to GHI, since these are the current three search strings.

4.6. +R{C,W,L}: Recall {Characters, Words, Lines} into Search Strings

These commands are like the corresponding commands without the + (see Section 7.5), except that instead of inserting the text into the buffer, they use it to set the current search strings. The various modifiers that can be used with the standard R{C,W,L} command, such as ., Q, and a count, also apply here.

Example: if you have just issued DL on a line consisting of “foobar”, then +RL sets the current search strings to the single search string FOOBAR.

Example: if you issue 3DL to delete three lines, say:

this is the first line
followed by the second line
then the third

then +RL results in the three search strings “THIS IS THE FIRST LINE”, “FOLLOWED BY THE SECOND LINE”, and “THEN THE THIRD”.

Example: DW which deletes, say, THEN, followed by +RW, makes THEN the current search string.

Example: Suppose you have two buffers A and B on the screen. A is a buffer of search strings, one per line, that you want to find in buffer B. Initially, put the cursor at the start of the first search string in A, then use .B to move to buffer B (anywhere in it). The following macro can then be used to find the first occurrence in B of the next word in the list:

.B<eol>.DW+RW<eol>.B<eol>1G.T<eol>

The macro works as follows:

Only the final screen is seen after the entire macro has been executed, so the effect is for the cursor to move to the first occurrence in B of the next search word. Additional occurrences of the same word can be found using .T<eol>.


previous   next   top   contents   index   framed top   this page unframed

MAINEDIT User's Guide, Chapter 4