R - Replace

To replace a character string with another.

Syntax

R{j}
or
R{U}{n}/string/replacement{/p{-q}}{*}
or
R{U}m-k/string/replacement{/p{-q}}{*}
or
R{U}m,n/string/replacement{/p{-q}}{*}

Syntax Elements

j The number of lines to be replaced, beginning with the current line.

This syntax causes the Insert mode to be entered. You are prompted for data to replace the number of lines specified. The Editor returns to command mode either when data has been entered for the specified number of lines or when a null line is entered. If a null line is entered, prompting for additional lines stops and the remaining lines you specified are not changed.

If j is not specified, the default is one (current line only).

U Indicates universal replacement of string by replacement. All occurrences of string are replaced by replacement. Without this or the * option, only the first occurrence of string on each line is replaced.

n The number of lines from (and including) the current line in which to perform the replacement.

m -k Specifies line m to line k.

m ,n Specifies n lines, starting at line m.

/ A delimiter separating the different parts of the command. It can be any non-numeric character (except a blank or minus sign) that does not appear in string or replacement. The delimiter terminating replacement is necessary only if further parameters follow, or if trailing blanks are to be included as part of the string.

Note that using the colon (:) as a delimiter anchors the search to the starting column (see Column Dependent Matching).

string A character string that specifies the text to be replaced. A null string matches the beginning of the line.

The caret character (^) can be used within the search string to match any single character (see Wildcard Character for more details).

replacement A character string that defines the replacement text. This string can be null. Only one delimiter separates string and replacement. The delimiter after replacement is only required:

An attribute mark (CTRL+^) can be specified at the end of replacement to indicate that the line should be terminated at that point. This can be used to remove unwanted characters from the end of a line.

p Specifies a starting column (see Column Dependent Matching).

q Specifies an ending column. If omitted, defaults to p. Ignored if less than p,

* Universal replacement specifier. An alternative to using the RU command. Note that the * can also precede the p and q parameters.

Operation

If you do not specify a number or range of lines, the replacement is performed on the current line.

If you specify a number or range of lines, all lines in which the search string was replaced are listed. Changed lines are listed in their updated form. Note that the line pointer is positioned at the last line in the range, and therefore might not be located at the last line listed.

Example - R

:ED F1 ABC
Top
.L99
001 ABCDEF
002 ABCDEF
003 ABCDEF
EOI 003
.T
Top
.R2
001 123ABC
002 XX+XX+AB
.F
Top
.L99
001 123ABC
002 XX+XX+AB
003 ABCDEF
EOI 003
.T
Top
.R99/AB/HHH
001 123HHHC
002 XX+XX+HHH
003 HHHCDEF
EOI 003
.F
Top
.R7:HHH::1-3
003 CDEF
EOI 003
.F
Top
.G2
002 XX+XX+HHH
.R/+/123/*
002 XX123XX123HHH
.F
Top
.G2
002 XX123XX123HHH
.R/3/3Ctrl+^
002 XX123
.F
Top
.2
002 XX123
.R
002 123XX
.F
Top
.2
002 123XXX
.




Contents of item ABC.





Replace 2 lines.
Type in the replacement lines.

Toggle the buffer.


Contents of item ABC after the replacement.





Replace string "AB" with the string "HHH".
The affected lines are listed.



Toggle the buffer.

Replace "HHH" in columns 1-3 with nothing.
The affected lines are listed.

Toggle the buffer.

Go to line 2.

Replace all occurrences of "+" with "123".
The affected line is listed.
Toggle the buffer.

Go to line 2.

Replace the first occurrence of "3" with "3 CTRL+^" to terminate the line.
Toggle the buffer.

Go to line 2.

Replace all of line 2 with new text.
New text for line 2.
Toggle the buffer.


New contents of line 2.

Example 1 - RU

:ED NAMES XNAMES
Top
.P
001 FRANCIS K. BUSHMAN
002 KERKES
003 MALCOLM K
004 IANNIS KENAKIS
005 KAVIER CUGAT
006 ALEKANDER THE GREAT
007 GROVER CLEVELAND ALEKANDER
008 KAVIERA HOLLANDER
EOI 008
.T
Top
.RU99/K/X
001 FRANCIS X. BUSHMAN
002 XERXES
003 MALCOLM X
004 IANNIS XENAXIS
005 XAVIER CUGAT
006 ALEXANDER THE GREAT
007 GROVER CLEVELAND ALEXANDER
008 XAVIERA HOLLANDER
EOI 008
.F
Top
.4
004 IANNIS XENAXIS
.R/AX/AK
004 IANNIS XENAKIS
.




Current contents of item XNAMES in file NAMES.









Replace all occurrences of 'K' with 'X'.
New contents of item XNAMES.








Toggle the buffer.



Change XENAXIS to its correct spelling - XENAKIS.

Example 2 - RU

:ED NAMES XNAMES
Top
.P
001 FRANCIS K. BUSHMAN
002 KERKES
003 MALCOLM K
004 IANNIS KENAKIS
005 KAVIER CUGAT
006 ALEKANDER THE GREAT
007 GROVER CLEVELAND ALEKANDER
008 KAVIERA HOLLANDER
EOI 008
.T
Top
.RU3,2/K/X
003 MALCOLM X
004 IANNIS XENAKIS
.F
Top
.P
001 FRANCIS K. BUSHMAN
002 KERKES
003 MALCOLM X
004 IANNIS XENAXIS
005 KAVIER CUGAT
006 ALEKANDER THE GREAT
007 GROVER CLEVELAND ALEKANDER
008 KAVIERA HOLLANDER
EOI 008
.




Current contents of item XNAMES in file NAMES.









Replace all occurrences of 'K' with 'X' on lines 3 and 4.

Toggle the buffer.


New contents of item XNAMES.