

To match zero or more occurrences of the last character, type an asterisk ( *) in the string. The search pattern / stringfinds strings that begin with either “m” or “d.” Conversely, / string finds strings that begin with any letter from “d” through “m.” To search for alternative characters in a string, enclose the alternatives in brackets. For example, to find the next occurrence of “disinformation” or “misinformation,” type:īecause this is a search for a string and not a word, this search pattern might also find such constructions as “misinformationalist” and “disinformationism.” ) in the string at the location to be matched. For example, to find the next occurrence of the word-as opposed to the string-“search”, type: Thus, to match a word, rather than a string, combine the end-of-word and beginning-of-word tags in the search pattern. To match the beginning of a word, type \ at the end of the string. Note that the period is escaped with a backslash. For example, to find the next line ending with “search.”, type: To match the end of a line, end the search string with a dollar sign ( $). For example, to find the next line beginning with “Search”, type: To match the beginning of a line, start the search string with a caret ( ^). You can make searches more precise by tagging the string with indicators for the following characteristics: 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. You can use these special characters as commands to the search function. For example, to search for the string “anything?” type /anything\? and press Return. To escape a special character, precede it with a backslash ( \). ^ * $ \ ?) have special significance to the search process and must be “escaped” when they are used in a search. If the string is not found, vi displays Pattern not found on the last line of the screen.Ĭertain special characters ( / & !. If vi finds the requested string, the cursor stops at its first occurrence. To change it back to the default, case-sensitive mode, type :set noic. 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. In this situation, the directions of n and N are reversed. To search backward in a file, you can use ? instead of /. Type n to go to the next occurrence of the string. For example, to find the string “meta,” type /meta followed by Return. vi positions the cursor at the next occurrence of the string.

To find a character string, type / followed by the string you want to search for, and then press Return. A string can be a grammatical word or it can be part of a word.

A string might include letters, numbers, punctuation, special characters, blank spaces, tabs, or carriage returns. Finding a Character StringĪ character string is one or more characters in succession. vi also has a powerful global replacement function. Vi provides several ways to find your place in a file by locating a specified string of characters.
