Skip to main content
  1. Posts/

Ripgrep Searching CheatSheet

··331 words·2 mins·
Tools
Table of Contents

Ripgrep is a command line tools that searches patterns under your current directory, like the good old grep, but with faster speed. In this post, I list some of the commonly-used flags for ripgrep.

commandDescription
rg image utils.pySearch in a single file utils.py
rg image src/Search in dir src/ recursively
rg imageSearch image in current dir recursively
rg '^We' test.txtRegex searching support (lines starting with We)
rg -i imageSearch image and ignore case (case-insensitive search)
rg -s imageSmart case search
rg -F '(test)'Search literally, i.e., without using regular expression
rg image -g '*.py'File globing (search in certain files), can be used multiple times
rg image -g '!*.py'Negative file globing (do not search in certain files)
rg image --type py or rg image -tpy1Search image in Python file
rg image -TpyDo not search image in Python file type
rg -l imageOnly show files containing image (Do not show the lines)
rg --files-without-match imageShow files not containing image
rg -v imageInverse search (search files not containing image)
rg -w imageSearch complete word
rg --countShow the number of matching lines in a file
rg --count-matchesShow the number of matchings in a file
rg neovim --statsShow the searching stat (how many matches, how many files searched etc.)

How to enable shell completion for ripgrep?
#

The binary release of ripgrep also include completion files for Bash, Zsh. When we extract the binary release, the completion file is under completion/_rg. For zsh, we should move this file to one of the paths in env variable $fpath.

How to exclude directories
#

To exclude directories, we also use the -g option. For example, to exclude dir1 and dir2, use the following command:

rg pattern -g '!dir1/' -g '!dir2/'
Changelog

update: 2020-12-03, add --stats option

References
#


  1. To list the supported filetypes, use rg --type-list↩︎

Related

Nerdfont Icon Missing after Wezterm Upgrade
·172 words·1 min
Tools Terminal Font Unicode
Benchmarking Your HTTP Service Using wrk
··450 words·3 mins
Tools Lua HTTP
How to Extract Key Frames from A Video with FFmpeg
··426 words·2 mins
Tools Ffmpeg Video