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:
-
when trailing blanks in replacement must be included.
-
when using the optional column (p-q) or replace all (*) specifications.
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
|
|
Example 1 - RU
|
|
Example 2 - RU
|
|