DEV Community

gokayburuc.dev
gokayburuc.dev

Posted on

Use Ripgrep as Default Grep Program in VIM or Neovim

Use Ripgrep as Default Grep Program in VIM or Neovim

/scre

Intro

Efficient search is essential when navigating large codebases. The traditional grep command works fine, but modern projects with nested folders, hidden files, and version control directories demand more speed and flexibility. That’s where ripgrep (rg) comes in — a blazing-fast search tool designed for developers. Integrating it with Vim or Neovim supercharges your workflow, letting you search instantly across your entire project without leaving the editor.


What is ripgrep?

Ripgrep is a command-line search tool written in Rust. It recursively searches your current directory for a regex pattern while respecting your .gitignore, .ignore, and .rgignore files. It’s significantly faster than traditional tools like grep, ack, or ag because it’s optimized for modern CPUs and uses efficient file traversal techniques.

Key features:

  • Fast — built on Rust’s regex engine and parallelized for multicore CPUs.
  • Smart — automatically ignores binary files and respects .gitignore.
  • Compatible — supports PCRE2 regex syntax and integrates smoothly with Vim/Neovim.
  • Versatile — can output results in formats readable by many editors and tools.

How To Install ripgrep

Ripgrep is available in most package managers. Here’s how to install it on different systems:

Debian/Ubuntu:

sudo apt install ripgrep
Enter fullscreen mode Exit fullscreen mode

Fedora:

sudo dnf install ripgrep
Enter fullscreen mode Exit fullscreen mode

Arch Linux:

sudo pacman -S ripgrep
Enter fullscreen mode Exit fullscreen mode

macOS (Homebrew):

brew install ripgrep
Enter fullscreen mode Exit fullscreen mode

Windows (Scoop):

scoop install ripgrep
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can download binaries directly from the official GitHub releases.


How to Configure ripgrep as Default Grep Program

Add the following snippet to your .vimrc or init.vim:

if executable('rg')
    set grepprg=rg\ --vimgrep\ --no-hidden\ --no-heading\
endif
Enter fullscreen mode Exit fullscreen mode

Explanation

  • if executable('rg') — ensures ripgrep is installed before configuring it.
  • grepprg — sets Vim’s internal search program to use ripgrep instead of system grep.
  • --vimgrep — formats the output so Vim can parse results into the quickfix list.
  • --no-hidden — ignores hidden files unless you specify otherwise.
  • --no-heading — removes redundant directory headers for cleaner output.

Once configured, commands like :grep pattern will use ripgrep automatically. You can then open matches in Vim’s quickfix window for easy navigation.


Adding Keymaps

You can create convenient shortcuts for common search tasks.
For example, to quickly find all TODO or FIX comments in your project:

nnoremap <silent><leader>td :silent grep! TODO: <Bar> copen<CR>
nnoremap <silent><leader>tf :silent grep! FIX: <Bar> copen<CR>
Enter fullscreen mode Exit fullscreen mode

Explanation

  • <leader>td — searches for TODO: in your project.
  • <leader>tf — searches for FIX: tags.
  • :silent grep! — runs the search quietly using ripgrep.
  • <Bar> copen<CR> — opens the quickfix window automatically to display results.

Tip: Customize <leader> in your .vimrc (commonly mapped to space or ,).


Outro and Conclusion

Replacing Vim’s default grep with ripgrep is a small change that makes a big difference. You get faster searches, smarter file handling, and seamless integration with modern codebases.

Once set up, you can jump between TODOs, FIX notes, or any keyword in milliseconds — turning Vim or Neovim into a lightning-fast search companion.

If you rely on project-wide navigation, this tweak is easily one of the most impactful upgrades you can make.

Top comments (0)