Search & Replace with Literals


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:

Initial Conditions
Madison·Angelica·Mcbride
Sarah·Kristine·Ryan
Daniel·Justin·Baker
Meagan·Linda·Harvey
Abigail·Julia·Lewis
Megan·Jacqueline·Morris
Preston·Daniel·Moore
Sheryl·Michelle·Hill
COMMANDTop1:1
:%s/Linda//n

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\>
Note

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:

Check the search pattern
Madison·Angelica·Mcbride
Sarah·Kristine·Ryan
Daniel·Justin·Baker
Meagan·Linda·Harvey
Abigail·Julia·Lewis
Megan·Jacqueline·Morris
Preston·Daniel·Moore
Sheryl·Michelle·Hill
NORMALTop1:1
1 match on 1 line

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:

Execute the subsitution
Madison·Angelica·Mcbride
Sarah·Kristine·Ryan
Daniel·Justin·Baker
Meagan·Barbara·Harvey
Abigail·Julia·Lewis
Megan·Jacqueline·Morris
Preston·Daniel·Moore
Sheryl·Michelle·Hill
NORMAL44%4:1