Searching for text and replacing it with literal strings is both the simplest and possibly most-common replacement operation, so let's start there.
Starting from the following buffer:
we would like to change "Linda" to "Barbara". As a first step, lets create the pattern to search for. We want to search the entire buffer, so we start with:
:%s/
Next, we want to match full-words "Linda" so we add anchors to enforce the match between word boundaries:
:%s/\<Linda\>
Given the content of this buffer the anchors are not technically necessary, but it is good practice to use them.
Since we have our search pattern, let's execute a search with the n
flag
to be sure that it performs as expected:
OK, looks good. Now, all that is left is to add our replacement text. In this case our replacement text is a simple literal string:
"%s/\<Linda\>/Barbara
Finally, lets execute the substitution: