Solaris Advanced User's Guide

Finding a Character String

A character string is one or more characters in succession. A string might include letters, numbers, punctuation, special characters, blank spaces, tabs, or carriage returns. A string can be a grammatical word or it can be part of a word.

To find a character string, type / followed by the string you want to search for, and then press Return. vi positions the cursor at the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return.

Type n to go to the next occurrence of the string. Type N to go to the previous occurrence.

To search backward in a file, you can use ? instead of /. In this situation, the directions of n and N are reversed.

Searches normally are case sensitive: a search for “china” will not find “China.” If you want vi to ignore case during a search, type :set ic. To change it back to the default, case-sensitive mode, type :set noic.

If vi finds the requested string, the cursor stops at its first occurrence. If the string is not found, vi displays Pattern not found on the last line of the screen.

Certain special characters ( / & ! . ^ * $ \ ?) have special significance to the search process and must be “escaped” when they are used in a search. To escape a special character, precede it with a backslash (\). For example, to search for the string “anything?” type /anything\? and press Return.

You can use these special characters as commands to the search function. If you want to search for a string that includes one or more of these characters, you must precede the special character with a backslash. To escape a backslash itself, type \\.