|
|
When searching for text, it is worth considering if you will want to return to your current position in the file. If so, you should either make a note of the current line number reported using <Ctrl>G, or put a marker in the file using the m command. See ``Placing markers'' for further details.
To start a search:
Assuming that you are at the top of the example
file (you could enter 1G or
:1 to go to the first line), and you want to find all
occurrences of the word ``sleep''. You enter
/sleep to find the first match:
And by opposing end them. To die, to sleep -
Pressing / and <Enter> subsequently finds the following
lines in turn:
No more - and by a sleep to say we end
Devoutly to be wished. To die, to sleep -
To sleep - perchance to dream: ay, there's the rub,
For in that sleep of death what dreams may come
This continues until the first occurrence in the file is found again:
And by opposing end them. To die, to sleep -
vi allows you to look for more general patterns of text using regular expressions. For a discussion of the regular expressions matched by vi, see ``Editor regular expressions''.