Use EditChange to replace all occurrences of a specified string of current session text characters with another specified string. Occurrences will be replaced in a specified column range for a specified group of lines.
EditChange may also be entered as EditC[hange] or C[hange].
The group of lines can be specified by pre-selecting the lines (see Selection) or by using the FCT operand. If neither a pre-selection or FCT operand is provided, the group of lines consists solely of the current line.
Required Operands
OSTR is the old string to be replaced. Up to 72 characters may be specified. If the value of OSTR begins with the backslash character (\), matching will use the Extended Search Pattern rules.
NSTR is the new string, or replacement. Up to 72 characters may be specified. Wherever OSTR is matched, NSTR will replace the characters that are matched.
Optional Operands
FCT specifies the number of lines to apply the change to. FCT may also be specified with an asterisk(*), that indicates all lines from the current line to end of session.
Default: 1.
ZONE is the column range within which the search and replacement will occur. Enter it in the format xxx-yyy where xxx and yyy are numbers between 1 and the session maximum line width. For example, ZONE=11-20 signifies columns 11 to 20. ZONE=5 is the same as ZONE=5-5, ZONE=5-* specifies columns 5 through the session maximum line width, and ZONE=-5 is the same as ZONE=1-5.
Default: current session zone.
CASE specifies an upper/lower case search and replace option. If CASE is U, NSTR and OSTR will be translated to upper case letters before searching or replacing. If CASE is M, NSTR and OSTR are used "as is". Session text is never translated before comparison as it sometimes is with the Find Commands. For example, if session CASE is U and you enter
=> change 'hello' 'good bye'
only instances of "HELLO" in upper case will be changed to "GOOD BYE" in upper case. For the same command, if session CASE is M, only instances of "hello" in lower case will be changed to "good bye" in lower case.
Default: Session case. See the CASE operand of the FileAlter and SessionAlter commands.
Upon completion of EditChange, the message line will display the number of lines scanned and the number of occurrences changed.
The % character in an Extended Search Pattern holds special relevance to the EditChangecommand. If there are two % characters in OSTR, they indicate where replacement by NSTR will start and end. If there is only one %, replacement runs from the % to the last non-pattern character in OSTR. If there are no % characters, replacement will be from the first to the last non-pattern characters in OSTR.
CAUTION
Be sure to be cautious when using the EditChange command; especially when it will affect many lines. It is quite easy to write a EditChange that will have undesirable effects. For example:
=> change "the" "a" *
This example will not only change the word "the" to the word "a", it will also change the word other to the word oar and the word there to the word are. You can protect against runaway changes in several ways.
File and restart the FileEdit session before entering EditChange. That way, if undesirable changes take place, you can issue SessionClose with the NOSAVE option to undo the results of EditChange.
Use Extended Search Pattern characters to further qualify EditChange For example, the command above could have been written more safely as:
=> change "\<the>" "a" *
Use Qualify to preview the lines that will be changed.
Use a combination of Locate and a one-line EditChange to view each line after it is changed. Each time you press ENTER, a new line will be found, changed and displayed until the Locate fails because it can't find any additional matches. For the above example:
=> &locate "the" case=m;change "the" "a"
Return Codes
OK Successful.
Examples
Replace all occurrences of the string "key" with the string "xkey" starting at the current line and proceeding through to the last line of the session:
=> change key,xkey,*
Replace all occurrences of the string "TXL" with the string "TXM" within the selected lines:
=> c TXL,TXM