6.2 Context-Sensitive ReplacementThe simplest global replacements substitute one word (or a phrase) for another. If you have typed a file with several misspellings (editer for editor ), you can do the global replacement: :%s/editer/editor/g 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/ The first For example, in this book, the SGML directives
:g/<keycap>/s/Esc/ESC/g 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: :g/ would search for lines containing string and substitute for that same string . Note that: :g/editer/s//editor/g has the same effect as: :%s/editer/editor/g You can save some typing by using the second form.
It is also possible to combine the |
|