Vim Recipes ‣ Searching ‣ Searching and Replacing
You want to replace all occurrences of one string with another.
For example, imagine you were using Vim to write a novel wherein there was a protaganist named Curtis. You decide to change his name to Excalibur to give him more panache. You want Vim to make these changes with the least possible effort.
Execute :%s/target/replacement/g to replace all occurrences of target with replacement. For example: :%s/Curtis/Excalibur/g.
The solution above replaces Curtis with Excalibur. The g flag at the end causes this operation to be performed globally, i.e. multiple times on each line, if necessary.
The % prefix indicates that the replacement should occur over the entire file. Had you previously visually selected text to which you want to constrain the search/replace operation omit the %, e.g. :s/Curtis/Excalibur/g. Or, prefix the command with a range to contstrain it that way, e.g. 2,20s/Curtis/Excalibur/g performs the operation over lines two to twenty.
The search string (Curtis in this example) doesn't have to be a literal string; it can be any Vim regular expression. The details of Vim's regular expressions are explained in the Creating Regular Expressions recipe, so I won't go into them here. Two tips, though: