DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Editing files

Searching for text

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:

  1. Type a slash (/); this takes the cursor to the bottom of the screen.

  2. Enter the text you want to find and press <Enter>. vi searches forward through the file looking for a matching text string. The cursor moves to the position of the next occurrence of text that matches.

  3. To find the next match, press n. Repeat this until you find the match you want.
Press N to search backward through the file instead of forward.

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'' and the regexp(M) manual page.


Next topic: Replacing and modifying text
Previous topic: Using the deletion buffers

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005