# r command (Editor processor)

The r command replaces the current line,
replaces a string of characters within the current line, or replaces
a string of characters within a specific range of lines.

## Syntax

```
 r{u}{#lines}/old.string/new.string{/{start.col{-end.col}}}
```

## Parameter(s)

| u | Indicates universal replace. |
| --- | --- |
| #lines | Specifies the number of lines to be replaced. |
| / | (forward-slash) Delimiter that can be any nonnumeric character. |
| old.string | If null, a new string is inserted at the beginning of the line. |
| new.string | If null, and the old string is found, the old string is deleted from the line. |
| start.col | Specifies the beginning column range in which strings are eligible for replacement. |
| end.col | Specifies the ending column range in which strings are eligible for replacement. |

## Description

Only the first occurrence of the old string is replaced with the new string. The
 ru form replaces all (universal) occurrences. If the number of lines is
 specified, the line pointer is incremented accordingly.

An r command, followed by pressing Enter, allows the replacement of an entire
 line. Pressing ENTER at the first position of the line returns control to the Editor command
 prompt and the line remains unchanged.

Multiple replacements may be performed on
a line without filing the data with the f command.

The `^` represents an attribute mark in the Editor. Used with the
 r command, it has the effect of terminating the line. See the following
 .r/abc/^ example.

Note: When using column ranges (see [c command (Editor processor)](https://d3codex.com/editor/c-command-editor-processor/)), the r command only works if there is
data in the attribute and it occurs within the specified column position,
or range of positions. It is not possible to replace using a column
range beyond the end of the attribute.

## Example(s)

Positions cursor at the beginning
of line `nnn` for replacement of the entire line. A
subsequent Enter leaves the line intact.

```

 r
 nnn _
```
Positions cursor at the beginning of each of the next
ten lines for entire line replacement.

```
 r10
```
Replaces the first 3 characters (wildcards or `^`) of the current line with null.
 That is, deletes the first three characters.

```
 r/^^^//
```
Replaces the first occurrence of the string, `abc`, with an attribute mark (`^`), terminating the line
prior to the string, `abc`.

```
 r/abc/^
```
Places the string, `abc`, at the beginning of the next ten lines.

```
 r10//abc
```
Replaces the first occurrence of the string, `abc`, with the string `xyz` in the current and the next
nine lines.

```
 r10/abc/xyz
```
Replaces all occurrences of the string, `abc`, with the string, `xyz`, in the current and next
nine lines.

```
 ru10/abc/xyz
```
Replaces the first occurrence of the string, `abc`, with the string
 `xyz` in the current and next nine lines when the string is found in column
 positions 5 through 9.

```
 r10/abc/xyz/5-9
```
Replaces all characters on the current attribute with *null*, leaving the current attribute intact, but empty.

```
 ru/^//
```
Replaces every occurrence of two spaces with one space,
from the current line through the end of the item.

```
 ru999/ / /
```

## See also

- [c command (Editor processor)](https://d3codex.com/editor/c-command-editor-processor/)
- [Error messages](https://d3codex.com/editor/error-messages/)
- [Editor overview](https://d3codex.com/editor/editor-overview/)
- [Wildcards](https://d3codex.com/editor/wildcards/)
- [^ command](https://d3codex.com/editor/caret-command/)

---
Source: https://d3codex.com/editor/r-command-editor-processor/ - part of the D3Codex reference.
