To search a file, type / (search forwards) or ? (search backwards) and enter the word.
Normally, Vim will check for upper and lower letters. But you can set two different options in your configuration file (~/.vimrc or similar):
set ignorecase
or
set smartcase
Examples:
pattern 'ignorecase' 'smartcase' matches ~
foo off - foo
foo on - foo Foo FOO
Foo on off foo Foo FOO
Foo on on Foo
\cfoo - - foo Foo FOO
foo\C - - foo
Other options:
:set incsearch - show match as search proceeds
:set hlsearch - search highlighting
Vim will jump to the first match. Hit Enter if you’re finished with typing. Then you can circle through all matches with n (forwards) or N (backwards).
You can also search for the current word. Press * and Vim will search forwards. With # Vim will search backwards.
Both commands will do an exact search. If your cursor is on the word for, it won’t match forwards. You can fuzzy search with g* or g#.
Hit / or ? and arrow keys for your search history.
Further Reading
- Vim Tips And Tricks: Searching
- Vim Search Commands by Alvin Alexander
- Mastering Vim Quickly by Jovica Ilic