S - Substitute.




$s;.*;whole new line;


It is general practice to use / as a delimiter in many commands. However, any non-alphanumeric character can also be used. The final delimiter may be omitted if O-S/ is in effect and the S command is immediately followed by a new-line.


S puts string in place of anything that matches pattern. If you do not specify an address, this happens only on the current line. If you specify one address, this happens on the given line instead. If you specify two addresses, this happens on all the lines between and including the two given lines. In this case, the first address must precede the second in the buffer.

S usually works on everything in the line that matches pattern. For example,


changes every A in the line into B. If you only want to change a particular A, put a number immediately after the S. For example,


changes only the first A into a B. Use negative numbers if you want to work from the end of the line instead of the beginning. For example,


turns the second last A into a B.

The string part of the S command can contain any character. However, if you want a new-line character in this string, you must put a \C immediately preceding the new-line; otherwise, FRED will think the new-line is the end of the command.

If string contains an & character and O+S& is in effect, FRED treats the & as if it stands for whatever pattern matched. For example,


doubles all occurrences of A or B or C. If you really want an & character in string, put a \C in front of it, as in


The O+S& option also gives special meaning to the tag characters in patterns like


The a after the closing brace is a tag character. In the string of an S command, it stands for whatever matched the pattern enclosed by the brace brackets. For example,


is equivalent to


If you do not want & to have its special meaning, put a \C in front of it, as in


This turns meow into bow-wa. (In order to use the special meaning of brace brackets in a pattern, you must turn them on with O+S{. Thus you need both O+S{ and O+S& to use tag characters.)

If you want to use the special meaning of & when O-S& is in effect, type \O&.

There are many special constructs that can be used in substitution patterns, but some of these constructs are not turned on by default. For a list of which constructs are turned on by default and which are not turned on, see "expl fred patterns".

At the end of the substitution operation, FRED sets "." to the last line where a substitution was made. FRED sets the count register to the number of substitutions that took place. If no substitutions were made, FRED sets the condition register FALSE; otherwise, FRED sets it to TRUE. FRED issues an error message if S fails to make any substitutions, unless the command was executing out of a buffer.

Copyright © 1998, Thinkage Ltd.