#print More Movement - Searching in the File The last, but certainly not least, method we'll look at for moving around in the file is searching. The command to search for a particular word or phrase or whatever is '/'. When you type a /, vi will move the cursor to the bottom of the screen, echo the / and wait. You then type in the text you want to search for and hit return. If the text exists anywhere in the file, vi will move the cursor forward to the next occurence. If it gets to the end of the file without finding it, vi will wrap around to the front of the file and continue searching. If you want vi to start searching in the backward direction, i.e, toward the beginning of the file, use ? instead of /. Note that ? is just a shifted / on most terminals. To repeat a previous search with the same text, just hit 'n', for 'next'. To repeat the search in the opposite direction, hit 'N'. Type 'ready' now to try out the search commands. #user #create Search Searching uses these commands: / = To search forward for some text ? = To search backward for some text n = To repeat the previous search (i.e. go on to the 'next' occurance) N = To repeat the previous search but in the opposite direction We'll see later how to specify a pattern to search for, rather than just straight text. This will make a lot of searches much easier. Oftentimes, you will do a search and then want to go back to where you were previously. The '' command (that's two single quotes) will move you back to the last place you were. This is a special case of a command we'll look at in more detail later, in the section on marking. -------------------------------------------------------------------------- # cat /usr/lib/learn/vi/longtext >> Search vi Search #next 5.1 10