Both Vim and Neovim have build-in command for searching in files called
vimgrep
. The main advantage of using vimgrep is that it’s
available on all platforms and by using vimgrep you can freely use vim/Neovim
on all platforms, including Windows.
For example, you want to search for vim
string across all files in
a directory. This is what you should do:
:cd /path/to/directory
. This command changes current directory, similar tocd
command in a terminal.:vimgrep vim **/*.html
. This command searches for string “vim” across all files in a current directory with “html” extension. To search across all files, use:vimgrep vim **/*
:copen
Open “quickfix window” with a list of matches. Now you can move through matches and open corresponding match by pressingEnter
.
You can also move between matches with :cnext
and :cprevious
commands
(even without opening a quickfix window).