This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the unix category.
Last Updated: 2024-11-21
rg --no-ignore
Say you want to search for $mobile(
. There are two issues:
rg -F
(or --fixed-strings)Thus you need to both use the rg flag AND ALSO escape the characters
rg -F \$mobile\)
This is used to avoid going deep into node_modules etc. when these are not ignored
rg --maxdepth 2
rg --files
rg --files-with-matches
or
rg -l
Say I have some code like this
translate('name')
translate('person')
How to get the translation strings inside the function calls?
# Just get bit inside the `translate` function scattered throughout the code
$ rg --only-matching "translate\('(.+)'\)" -r '$1'
# - `-r` is group number
# `--only-matching` removes the rest of the line
rg --no-header needle haystack
Use a .ignore
file in your root directory to override how ripgrep uses the gitignore file
e.g.
# Ensure the ripgrep actually searches node_modules e.g. in nvim
!node_modules/
By default this is disabled. Enable with
rg -s SOME_VAR
By default rg will match within words:
echo 'play allegro le' | rg 'le'
> play al*le*gro *le*
Use \b
to delineate word boundaries:
echo 'play allegro le' | rg '\ble\b'
play allegro le