Search is an invaluable tool that’s very easy to use in Vim.
/ and you will see
/ appear in the tray at the bottom of Vim. Start typing what you are
searching for, then hit enter to go to the first match.
/<string> will search for next occurrences of that string.
?<string> will search for previous occurrences that string.
enter takes you to the first match.
Cycle through matches:
n go to next match
N go to previous match
You can turn an option on like this:
Some options are boolean. To turn them off, type:
Other options take a parameter:
You can inquire about the current state of an option:
There are two options that I recomend you turn on for searching.
First, set search to ignore the case of characters.
:set ignorecase, or
Second, turn on “smartcase”. If you type in a search pattern that is all lowercase then smartcase will show both lower and uppercase matches. However, if you type a single uppercase character then smartcase will become case sensitive.
Smartcase gives you the best of both worlds. You don’t have to type uppercase characters when casually searching, but if you need to find a specific constant or class name, which typically has an uppercase character, you can weed out all the lowercase matches by typing with the actual case.
Unfortunately, both of these settings default to off. You can put them in your vimrc file so that you don’t have to type them every time you start Vim. We’ll cover vimrc’s in a later chapter.
* will search for the word under the cursor. You can still use
N to cycle through the results.