Skip to main content

Editor Integration

rg is the default search engine for many modern editors and fuzzy finders. Understanding these integrations multiplies its power.

VSCode​

VSCode uses rg under the hood for its "Find in Files" (Ctrl+Shift+F). You can also set rg as the external search engine.

The .vscode/settings.json snippet to exclude extra paths:

{
"search.exclude": {
"**/node_modules": true,
"**/dist": true,
"**/.git": true
}
}

Vim / Neovim: :grep with rg​

Set rg as Vim's grep program:

" ~/.vimrc
set grepprg=rg\ --vimgrep\ --smart-case
set grepformat=%f:%l:%c:%m

" Now use: :grep "pattern"
" Then: :copen to view results

Neovim: Telescope + rg​

telescope.nvim uses rg as the live grep backend:

-- init.lua
require('telescope').setup({
defaults = {
vimgrep_arguments = {
'rg', '--color=never', '--no-heading',
'--with-filename', '--line-number',
'--column', '--smart-case'
}
}
})

-- Keybinding
vim.keymap.set('n', '<leader>g', require('telescope.builtin').live_grep)

fzf Integration​

Combine rg with fzf for interactive fuzzy searching:

# Interactively search and open in vim
rg --files | fzf | xargs vim

# Interactively search file CONTENTS and jump to the line
rg --no-heading --line-number "" | fzf --delimiter=: \
--preview 'bat --highlight-line {2} {1}' \
--bind 'enter:execute(vim +{2} {1})'

Add to ~/.bashrc or ~/.zshrc:

# rgg: search and interactively pick a result to open
rgg() {
local file line
read -r file line < <(
rg --no-heading -n "$@" |
fzf --delimiter=':' --nth=1,2,3 |
awk -F: '{print $1, $2}'
)
[[ -n "$file" ]] && ${EDITOR:-vim} +"$line" "$file"
}

Now use: rgg "TODO" → see results in fzf → press Enter → opens in your editor at that line.