Replace

Key

CTRL+L

The Replace function performs a find-and-replace operation on the current file, prompting for find and replacement strings. Replace substitutes all matches of the search pattern without prompting for confirmation.

Replace (CTRL+L)

Performs the replacement from the cursor to the end of the file, wrapping around the end of the file if the Searchwrap switch is on.

Arg boxarg | linearg | streamarg Replace (ALT+A boxarg | linearg | streamarg CTRL+L)

Performs the replacement over the selected area.

Note that PWB does not adjust the selection at each replacement for changes in the length of the text. For boxarg and streamarg, PWB may replace text that was not included in the original selection or miss text included in the original selection.

Arg mark Replace (ALT+A mark CTRL+L)

Performs the replacement on text from the cursor to the specified mark. It searches the range of text as if it were selected, according to the current selection mode. The mark argument cannot be a line number.

Arg number Replace (ALT+A number CTRL+L)

Performs the replacement over the specified number of lines, starting with the current line.

Arg Arg ... Replace (ALT+A ALT+A ... CTRL+L)

As above except using regular expressions.

Meta ... Replace (F9 ... CTRL+L)

As above except the sense of the Case switch is reversed for the operation.

Returns

TrueAt least one replacement was performed.

FalseString not found, or invalid pattern.

See

Qreplace, Searchwrap

Example

To use the replace function in a macro, use the phrase:

...Replace "pattern" Newline "replacement" Newline +>found...

Enter the replies to the prompts as you would when executing Replace interactively. This example also shows where to place the conditional to test the result of Replace.

You can specify special characters in the find-and-replacement strings by using escape sequences similar to those in the C language. Note that backslashes in the macro string must be doubled.

To restore the usual prompts, use the phrase:

...Replace <

To use an empty replacement text (replace with nothing), use the following phrase:

...Replace "pattern" Newline " " Cdelete Newline...

If you find that you write many macros with empty replacements, the common phrase can be placed in a macro, as follows:

nothing := " " Cdelete Newline

In addition, macro definitions can be more readable with the following definition:

with := Newline

With these definitions, you can write:

... Replace "pattern" with nothing ...