WezM.net Menu

Using ripgrep With Vim

Published on Wed, 28 September 2016

ripgrep (rg) is a new text search tool by Andrew Gallant:

ripgrep combines the usability of The Silver Searcher (an ack clone) with the raw performance of GNU grep. ripgrep is fast, cross platform (with binaries available for Linux, Mac and Windows) and written in Rust.

Andrew has written in extensive detail on the benchmarking he did, which shows ripgrep is one of the fastest and most correct tools of this nature. To make use of ripgrep within vim here are a few options:

Set grepprg, which is used by :grep to search a project and add the matches to the quickfix list:

if executable("rg")
    set grepprg=rg\ --vimgrep\ --no-heading
    set grepformat=%f:%l:%c:%m,%f:%l:%m

For use with ack.vim set g:ackprg as follows. Now when you run :Ack it will use rg instead:

let g:ackprg = 'rg --vimgrep --no-heading'

One of my favourite plugins, fzf.vim has built-in support for ag. I’ve created an experimental fork that adds support for rg to it. My fork adds the :Rg user command, which works the same way as the existing :Ag command. To use my version of the plugin with vim-plug add the following to your .vimrc:

Plug 'wezm/fzf.vim', { 'branch': 'rg' }

The line will be similar in Vundle or pathogen.

Comment icon Something to Add?

Contact me by email or Twitter if you have a comment, correction or just want to get in touch.