PRACTICAL GUIDE
ripgrep in your daily workflow
ripgrep (rg) is a regex-powered code search tool that is fast
enough to change how you work. It searches recursively by default, skips anything in your .gitignore, ignores binary files, and runs in linear time. This
is the short, practical path to using it well in the terminal and in Neovim.
THE 10-SECOND VERSION
Ninety percent of daily use is one command. Run it from your project root:
rg pattern
That searches every tracked file under the current directory. From there you narrow: add -w for whole words, -t to pick a language, -g to filter by file name, or -l to get just the matching file names. Everything else below is
a refinement of this one move.
ESSENTIAL FLAGS
-i / -s Force case-insensitive / case-sensitive-S, --smart-case Case-insensitive unless the pattern has a capital letter-w Match whole words only-F Fixed string - treat the pattern as literal text, no regex-l List only the file names that contain a match-c Count matches per file-o Print only the matched part, not the whole line-v Invert - show lines that do NOT match-A n / -B n / -C n Show n lines after / before / around each match-t lang / -T lang Only / never search a file type (rg --type-list to see them)-g 'glob' Filter by glob, e.g. -g '*.ts' or exclude with -g '!*.test.ts'--hidden Include dotfiles and hidden directories-u / -uu / -uuu Unrestrict: ignore .gitignore / also hidden / also binary-P Use PCRE2 - enables lookarounds and backreferences-U, --multiline Let a pattern span multiple lines-r "$1" Preview a replacement (does not write files)DAILY CLI RECIPES
rg -w parseConfig
rg -n 'TODO|FIXME'
Line numbers are on by default when printing to a terminal.
rg -trust 'fn main'
rg -trust = Rust files. Use rg --type-list to see every built-in type.
rg 'useEffect' src -g '!*.test.*'
rg -l "deprecated" | xargs nvim
rg -l prints file names; xargs feeds them straight into your editor.
rg --files | rg config
rg --files lists every file rg would search, honoring .gitignore.
rg -P 'price:\s*\K\d+'
\K drops everything before it from the match - PCRE2 only.
rg 'oldName' -r 'newName'
Shows what each line would become. It does not edit files - pipe to sd or use Neovim to apply.
INSIDE NEOVIM
1. MAKE :grep USE RIPGREP
Point Neovim's built-in grep at rg so :grep fills the quickfix
list. In your init.lua:
vim.o.grepprg = 'rg --vimgrep --smart-case' vim.o.grepformat = '%f:%l:%c:%m'
Now :grep useEffect populates the quickfix list and :copen opens it. Jump between hits with :cnext and :cprev.
2. INTERACTIVE FUZZY SEARCH
Telescope and fzf-lua both use ripgrep under the hood for live, as-you-type search. Two bindings cover most days:
-- Telescope
vim.keymap.set('n', '<leader>fg', '<cmd>Telescope live_grep<cr>') -- search everything
vim.keymap.set('n', '<leader>fw', '<cmd>Telescope grep_string<cr>') -- word under cursor live_grep searches the whole project as you type; grep_string searches the word under the cursor or your visual
selection. fzf-lua has the same pair: :FzfLua live_grep and :FzfLua grep_cword.
3. PROJECT-WIDE SEARCH AND REPLACE
Find with rg, then change every hit using the quickfix list:
:grep oldName :cfdo %s/oldName/newName/ge | update
:cfdo runs a command in every file in the quickfix list; %s/.../.../ge does the substitution (the e flag ignores files with no match) and | update saves. For a visual diff-style experience instead, grug-far.nvim and nvim-spectre are rg-powered find-and-replace panels.
MAKE IT YOURS
Stop retyping the same flags. Point ripgrep at a config file - one flag per line - and it applies them to every search:
# ~/.config/ripgrep/ripgreprc --smart-case --hidden --glob=!.git/* --max-columns=160
Then tell ripgrep where it lives by exporting the path in your shell rc:
export RIPGREP_CONFIG_PATH="$HOME/.config/ripgrep/ripgreprc"
With --smart-case as a default you rarely touch -i again, and --hidden means
you stop missing dotfiles.
THE REGEX BEHIND IT
By default ripgrep uses the Rust regex engine: extremely fast and guaranteed linear time, which
is why it never hangs. The trade-off is that it does not support lookarounds or backreferences.
When you genuinely need those, add -P to switch to PCRE2 - the
same family as the patterns in the lessons here. Everything else (character classes,
quantifiers, anchors, groups, alternation) works exactly like the cheatsheet shows.
THE PATTERNS ARE THE HARD PART
ripgrep is only as good as the regex you feed it. The free course drills every construct with live, checked exercises, and the tester lets you build a pattern before you paste it into rg.