rg
cli options-F, --fixed-strings |
Fixed String Matches |
-t py |
select only python files |
-w, --word-regexp |
Word Regexp |
-f, --file PATTERNFILE |
search for all patterns, one pattern per line |
-s |
case sensitive |
-i |
case insensitive |
-S |
smart case |
-g "**/tests/**" |
search only tests files with glob |
-g "!**/tests/**" |
don’t search test files with inverse glob ! |
--stats |
number of matches, number of line matches |
--sort created/modified |
sort results by file created/modified time |
-p, --pretty |
rg -p foo | less , pipe color to other program |
Rg | Vim | |
---|---|---|
zero or more | ? |
\? |
1 or more | + |
\+ |
precise number of matches | {n,m} |
\{n,m} |
word boundary | \b |
\< \> |
multiple patterns or | | |
\| |
non greedy | .*? |
.\{-} |
line starts with | ^ |
^ |
line ends with | $ |
$ |
group | ( ) |
\( \) |
back reference | not supported | \1 \2 \3 |
Example: to match company
and companies
compan\(y\|ies\)
compan(y|ies)
Find Python Function Definitions and Usages
# this prints Definitions too because I don't know how to ignore lines
# starts with `def`
#
# [^,] for removing imports
rg --multiline --multiline-dotall 'foo_function_name\(.*?\)[^,]' -g "!**/tests**"
foo_?bar
searches for foo_bar
,
FOO_BAR
, FOOBAR
, fooBar
it works because
_?
means _
is optional, i.e. the searched
words can contain 0 or 1 _
rg
result into pasteboard for PR description…rg foo --heading --line-number | pbcopy
Example output below
dev_notes.md
65:## Usage Example Of curo_request_kwargs
67:`_curo_request`