Lesson 3 | Searching for text in vi |
Objective | Use vi commands to search for text. |
Command | Action |
/pattern | Search forward for pattern |
?pattern | Search backward for pattern |
n | Repeat search in the same direction |
N | Repeat search in the opposite direction |
/
and ?
commands behave somewhat like ex
commands, because the /
and ?
appear on the status line. Also, you must press Enter after typing the pattern. After finding a pattern using the /
or ?
command, you can use n
or N
to search for the next occurrence.
The n
and N
commands are regular vi commands. They take effect immediately, with no need to press Enter.
.
, [ ]
, *,
^
and $
. They have the same meanings as when they are used with grep
commands.\
. to search for an actual period.
:ab
command to abbreviate text.