239 lines
7.2 KiB
HTML
239 lines
7.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
|
|
<meta http-equiv="X-Content-Type-Options" content="nosniff">
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
<link rel="icon" type="image/x-icon" href="../favicon.ico">
|
|
<script>
|
|
// Apply theme immediately to prevent flash
|
|
(function() {
|
|
const theme = localStorage.getItem('theme') ||
|
|
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
})();
|
|
</script>
|
|
<title>ripgrep Cheatsheet - Cheatsheets - Launch Pad</title>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
|
|
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
|
|
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
|
|
</button>
|
|
<br/><br/>
|
|
<div class="name">
|
|
__ _______________________ _________._________________________
|
|
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
|
|
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
|
|
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
|
|
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
|
|
\/ \/ \/ \/ \/ \/ \/
|
|
</div>
|
|
<div class="blog-page-header">
|
|
<div class="blog-header-content">
|
|
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
|
|
</a>
|
|
<h1 class="blog-page-title">ripgrep Cheatsheet</h1>
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-container">
|
|
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="blog-post">
|
|
<div class="blog-post-content">
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
<hr>
|
|
<p>ripgrep (rg) is a fast text search tool that recursively searches directories for a regex pattern. Faster than grep, respects .gitignore by default, and has excellent Unicode support.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>rg pattern - Search in current directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rg pattern path/ - Search in directory</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rg -i pattern - Case-insensitive search</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rg -w pattern - Whole word match</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rg -l pattern - List matching files only</li>
|
|
</ul>
|
|
<ul>
|
|
<li>rg -c pattern - Count matches per file</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Search Options</h2>
|
|
<ul>
|
|
<li>-i - Case-insensitive</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-w - Whole word</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-v - Invert match</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-x - Match entire line</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-F - Fixed string (no regex)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-e pattern - Pattern to search</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-f file - Patterns from file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-g pattern - Glob pattern</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Output Options</h2>
|
|
<ul>
|
|
<li>-l - List files only</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-L - List files without matches</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-c - Count matches per file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--count-matches - Count matches (not lines)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-n - Show line numbers</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-N - No line numbers</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-C N - Context lines (before and after)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-A N - Lines after match</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-B N - Lines before match</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-H - Show filename (default)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-h - No filename</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--color always - Always colorize</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--color never - Never colorize</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--color auto - Colorize when outputting to terminal</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>File Options</h2>
|
|
<ul>
|
|
<li>-t type - Search only file type</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-T type - Exclude file type</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-g pattern - Include glob pattern</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-g !pattern - Exclude glob pattern</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--type-list - List all file types</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--no-ignore - Don't respect ignore files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>--ignore-case - Case-insensitive matching</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-u - Unrestricted search (like --no-ignore)</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-uu - Also search hidden files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>-uuu - Also search binary files</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Basic Search</h3>
|
|
<pre><code>rg "function"</code></pre>
|
|
<p>Search for "function" in current directory.</p>
|
|
<h3>Case-Insensitive</h3>
|
|
<pre><code>rg -i "error"</code></pre>
|
|
<p>Search case-insensitively.</p>
|
|
<h3>List Files</h3>
|
|
<pre><code>rg -l "TODO"</code></pre>
|
|
<p>List files containing "TODO".</p>
|
|
<h3>With Context</h3>
|
|
<pre><code>rg -C 3 "pattern"</code></pre>
|
|
<p>Show 3 lines before and after.</p>
|
|
<h4>Specific File Type</h4>
|
|
<pre><code>rg -t py "import"</code></pre>
|
|
<p>Search only Python files.</p>
|
|
<h3>Exclude Type</h3>
|
|
<pre><code>rg -T js "function"</code></pre>
|
|
<p>Search excluding JavaScript files.</p>
|
|
<h3>Whole Word</h3>
|
|
<pre><code>rg -w "test"</code></pre>
|
|
<p>Match whole word only.</p>
|
|
<h3>Fixed String</h3>
|
|
<pre><code>rg -F "*.txt"</code></pre>
|
|
<p>Search literal string (no regex).</p>
|
|
<h3>Count Matches</h3>
|
|
<pre><code>rg -c "error"</code></pre>
|
|
<p>Count matches per file.</p>
|
|
<h3>Unrestricted</h3>
|
|
<pre><code>rg -u "pattern"</code></pre>
|
|
<p>Ignore .gitignore and other ignore files.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Much faster than grep for large codebases</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Respects .gitignore by default</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -i for case-insensitive search</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -l to just list files</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -t to filter by file type</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -C for context around matches</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Excellent Unicode support</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Great for code searching</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|