Using :set hlsearch will highlight all the matches in yellow allowing you to scan the file easily for matches. That may not be what you want though, after searching, :g//p will give you the listed matches
if you want to look at this list and jump quickly between the matches, consider using
:vimgrep example %
or
:grep example %
This will populate the "error list" with all of the matches so that you can use :copen to list them all in the quickfix buffer, press enter on a particular line to jump to that match, or use commands like :cn and :cp to go back and forth.
Another possibility is to use the include file search commands.
[I
This will list all occurrences of the word under the cursor. It may be more than you need though, because it will also search any files that are included in the current file.
But the nice thing about this command is that the search result display also shows a count of the number of matches, in addition to the line number of each match.
:help include-search
to see lots of variants.
A note about
:g//p
This can be reduced further to
:g//
because, as others have said, p(rint) is the default action.
Just learned a new one: the Location List!
Type :lvim foo % to search for foo in the current file and enter all matches containing foo into the location list.
Type :lopen to open the location list in the quickfix window, which is fully navigable as usual.
Use :lnext/:lprevious to to through the list (use tpope/unimpaired mappings for the best experience)
" put in your ~/.vimrc file
" START search related configs and helps
"
" ignore case when searching
set ignorecase
" search as characters are entered, as you type in more characters, the search is refined
set incsearch
" highlight matches, in normal mode try typing * or even g* when cursor on string
set hlsearch
" yank those cheat commands, in normal mode type q: than p to paste in the opened cmdline
" how-to search for a string recursively
" :grep! "\<doLogErrorMsg\>" . -r
"
" how-to search recursively , omit log and git files
" :vimgrep /srch/ `find . -type f \| grep -v .git \| grep -v .log`
" :vimgrep /srch/ `find . -type f -name '*.pm' -o -name '*.pl'`
"
" how-to search for the "srch" from the current dir recursively in the shell
" vim -c ':vimgrep /srch/ `find . -type f \| grep -v .git \| grep -v .log`'
"
" how-to highlight the after the search the searchable string
" in normmal mode press g* when the cursor is on a matched string
" how-to jump between the search matches - open the quick fix window by
" :copen 22
" how-to to close the quick fix window
" :ccl
" F5 will find the next occurrence after vimgrep
map <F5> :cp!<CR>
" F6 will find the previous occurrence after vimgrep
map <F6> :cn!<CR>
" F8 search for word under the cursor recursively , :copen , to close -> :ccl
nnoremap <F8> :grep! "\<<cword>\>" . -r<CR>:copen 33<CR>
" omit a dir from all searches to perform globally
set wildignore+=**/node_modules/**
" use perl regexes - src: http://andrewradev.com/2011/05/08/vim-regexes/
noremap / /\v
"
" STOP search related configs and helps