Perhaps an example would help you. Suppose you have the following text file
Code:
abcdefg
faaaag
accxxcck
abbde
and want to use
vi to search and replace all instances of 'b', 'c', 'd' and 'e' with 'Q',
you can do with the following command ":%s/[b-e]/Q/g' which results in
Code:
aQQQQfg
faaaag
aQQxxQQk
aQQQQ
Here is an except from a typical
vi man page regarding substitute:
Code:
[range] s[ubstitute] [/pattern/replace/] [options] [count] [flags]
[range] & [options] [count] [flags]
[range] ~ [options] [count] [flags]
Make substitutions. In the substitution string, the characters ~ and %
may have special meanings. If the entire replace pattern is a percent
sign (%), the previous replacement pattern is used. (This can be
useful for repeating substitutions that contain back references.) The
special character ~ inserts the previous replacement string into this
replacement string.
The options can be any of the following:
c
Ask for confirmation before replacing the text.
g
Perform the replacement on all occurrences of the regular
expression on the line.
r
If no regular expression was specified, use the most recent
regular expression (used for a search) rather than the same
regular expression as used for the last substitute command.