Include preceding context lines.
Section: Context lines
Show lines before each match
bash
bash
rg -B 2 'panic!' src/Explanation
Useful for reading the setup or declaration that leads into a match.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Context lines
Customize context separators
Make grouped output easier to parse visually.
Print all lines but highlight matches
Stream a file through rg without dropping non-matching lines.
Disable file headings
Print file names inline per match instead of grouped headings.
Print summary statistics
Show counts and timing information at the end of a search.