How do I configure Vim to use ripgrep as its built-in grep program?
Answer
:set grepprg=rg\ --vimgrep
Explanation
Vim's :grep command uses an external program to search files and populate the quickfix list. By changing grepprg to use ripgrep (rg), you get dramatically faster searches with smart defaults like respecting .gitignore and skipping binary files.
How it works
grepprg— the external program Vim uses for:grepgrepformat— how to parse the program's output into quickfix entriesrg --vimgrep— outputs in the format Vim expects (file:line:col:match):grep patternthen uses ripgrep instead of system grep
Example
" In your vimrc
set grepprg=rg\ --vimgrep
set grepformat=%f:%l:%c:%m
" Now :grep uses ripgrep
:grep 'TODO' src/
:copen
Quickfix list:
src/main.py|15 col 5| # TODO: refactor this
src/utils.py|42 col 5| # TODO: add error handling
Tips
- Add
--smart-casefor case-insensitive matching when pattern is lowercase rgautomatically skips.git/,node_modules/, and files in.gitignore- Use
:grep!(with bang) to not jump to the first result - For async grep, use plugins like
vim-dispatchor Neovim's job control