How do I fuzzy search inside file contents across a project in Vim?
Answer
:Rg
Explanation
The fzf.vim plugin combines the blazing-fast fzf fuzzy finder with ripgrep to let you search inside every file in your project interactively. Running :Rg opens a full-screen fuzzy search prompt that queries file contents in real time, displaying matching lines with syntax-highlighted previews — far faster and more ergonomic than :vimgrep or :grep.
How it works
With fzf.vim installed and rg (ripgrep) available on your system, run:
:Rg search_term
This instantly searches all files in your project for search_term and opens an interactive fzf window where you can:
- Refine results by typing additional filter text
- Preview matches with surrounding context in a side pane
- Open a result by pressing
<CR>to jump directly to the matching line
Running :Rg with no argument opens the prompt for you to type your query interactively.
Key bindings in the fzf window
<CR> " open the selected match in the current window
<C-t> " open in a new tab
<C-x> " open in a horizontal split
<C-v> " open in a vertical split
<Tab> " select multiple results
<S-Tab> " deselect a result
<CR> " with multiple selections, populate the quickfix list
Multi-select to quickfix
One of the most powerful patterns is selecting multiple results with <Tab>, then pressing <CR> to send them all to the quickfix list. From there, you can use :cnext and :cprev (or ]q / [q with vim-unimpaired) to jump through every match, or :cfdo to run a command across all matched files.
Scoping the search
You can pass ripgrep flags directly to narrow the search:
:Rg -t py import " search only Python files
:Rg -g '!test*' handler " exclude test files
:Rg --no-ignore TODO " include gitignored files
:Rg -w fetch " match whole word only
Related fzf.vim commands
:Files " fuzzy-find files by name
:Buffers " fuzzy-find open buffers
:Lines " search across all open buffer lines
:BLines " search within the current buffer
:History " recently opened files
:Commits " browse Git commits with fzf
Tips
- Map
:Rgto a quick shortcut for instant access:nnoremap <Leader>rg :Rg<CR> - Ripgrep respects
.gitignoreby default, so generated files andnode_modulesare excluded automatically - Use
:Rg!(with a bang) to open the search in fullscreen mode with a larger preview window - Install the
batcommand for syntax-highlighted previews inside the fzf window - Combine multi-select with
:cfdo %s/old/new/gc | updateto perform a project-wide search and replace with confirmation