Search or replace with regular expressions
Regular expressions (or regexes) are wonderful, and you should know how to use them. Vim, as is custom among regex implementations, has its own flavor of regex. However, once you learn one, you’ll be comfortable with all of them.
First, let’s talk about the regular (that is, the normal) search and replace command.
Search and replace
Vim supports search and replace through the :substitute
command, most often abbreviated to :s
. By default, :s
will replace one substring with another in a current line. It has the following format:
:s/<find-this>/<replace-with-this>/<flags>
The flags are optional, and you shouldn’t worry about them for now. To try it, open welcome.py
, navigate to the line containing egg
(for example, with /egg
), and execute the following:
Reminder
/
followed by a substring allows you to search for a substring and will move the cursor to the line of the first match.
...