This substitutes editor for every occurrence of editer throughout the file.
There is a second, slightly more complex syntax for global replacement. This syntax lets you search for a pattern, and then, once you find the line with the pattern, make a substitution on a string different from the pattern. You can think of this as context-sensitive replacement.
The syntax is as follows:
g tells the command to operate on all lines of a file.
pattern identifies the lines on which a substitution is to take
On those lines containing pattern, ex is to
s) for old the characters in new.
g indicates that the substitution is to
occur globally on that line.
For example, in this handbook, the macro .BX places a box around [ESC] to show the ESCAPE key. You want [ESC] to be all in caps, but you don't want to change any instances of Escape that might be in the text. To change instances of Esc to ESC only when Esc is on a line starting with the .BX macro, you could enter:
If the pattern being used to find the line is the same as the one you want to change, you don't have to repeat it. The command:
would search for lines containing string and substitute for that same string.
has the same effect as:
You can save some typing by using the second form.
It is also possible to combine the
:g command with
:co and other ex commands besides
As we'll show, you can thus make global deletions, moves and copies.