Text Search Guide
July 21, 2026 ยท View on GitHub
Note: legacy text-search dispatcher names are internal implementation details. The AI-facing default path for text search is
exec_command.cmdwithrg.
Shell examples follow the active shell prompt profile. Linux, macOS, and WSL use the Unix-like profile by default; native Windows uses PowerShell. VT Code does not rewrite GNU flags for macOS BSD tools and does not translate Unix commands to PowerShell. Use WSL when you want Unix-like workflows on Windows.
Overview
Use ripgrep (rg) through exec_command.cmd for fast text and regex
search across codebases. Use shell grep only when rg is unavailable or when
you need a host-specific grep feature. The advanced profile also provides
code_search for one bounded literal query (or |-separated literal
alternatives, e.g. tokio|async-std|runtime) across definitions, syntactic
usages, text, and paths.
Architecture
- Backend:
rgon PATH, orgrepas a fallback - Search type: regex by default, literal string matching with
rg -F - File filtering:
rg --glob,rg -t, path arguments, and size limits - Performance:
rgrespects.gitignoreand.ignorefiles by default - Output control: line numbers, column numbers, filename-only output, and nearby lines are shell flags
Basic Usage
Call exec_command with a shell command:
{
"cmd": "rg -n \"TODO\" src"
}
Simple Text Search
rg -n "TODO" src
Function Definition Search
rg -n -C 3 --glob "**/*.rs" "^(pub )?fn \\w+\\(" .
Import Statement Search
rg -n -i --glob "**/*.ts" "^import\\s.*from" .
Flag Reference
Core Flags
| Need | rg command form |
|---|---|
| Search under a path | rg "TODO" src |
| Show line numbers | rg -n "TODO" src |
| Limit result volume | `rg -n "TODO" src |
| Return only filenames | rg -l "TODO" src |
Pattern Matching
| Need | rg flag |
|---|---|
| Literal string search | -F |
| Case-insensitive search | -i |
| Case-sensitive search | -s |
| Smart-case search | -S |
| Whole-word search | -w |
| Invert a match | -v |
| Show only matched text | -o |
File Filtering
| Need | rg flag |
|---|---|
| Glob file filter | --glob "**/*.rs" |
| Language type filter | -t rust, -t python, -t ts |
| Skip large files | --max-filesize 5M |
| Search hidden files | --hidden |
| Include ignored files | --no-ignore |
| Search binary files | -a |
Output Formatting
| Need | rg flag |
|---|---|
| Nearby lines | -C 3 |
| Lines before matches | -B 2 |
| Lines after matches | -A 2 |
| Column numbers | --column |
| Trim leading whitespace | --trim |
| JSON output for scripts | --json |
Common Patterns
Finding Functions
Rust functions:
rg -n --glob "**/*.rs" "^(pub )?async fn \\w+|^(pub )?fn \\w+" .
TypeScript and JavaScript functions:
rg -n --glob "**/*.ts" "^(export )?function \\w+|^const \\w+ = (async )?\\(" .
Python functions:
rg -n -t python "^def \\w+\\(" .
Finding Error Handling
Rust panics and unwraps:
rg -n -C 2 -t rust "panic!|unwrap\\(|expect\\(" .
Try-catch blocks:
rg -n --glob "**/*.ts" "try\\s*\\{|catch\\s*\\(|throw " .
Finding Imports and Exports
TypeScript imports:
rg -n --glob "**/*.ts" "^import\\s+.*from\\s+['\\\"]" .
Python imports:
rg -n -t python "^import |^from .* import " .
Finding TODOs and FIXMEs
All comment markers:
rg -n -C 1 "(TODO|FIXME|HACK|BUG|XXX)[:\\s]" .
Language-specific TODOs:
rg -n -C 1 -t rust "// TODO|# TODO" .
Finding API Calls
HTTP verbs:
rg -n -C 2 --glob "src/**/*.ts" "\\.(get|post|put|delete|patch)\\(" .
Database queries:
rg -n -i --glob "**/*.sql" "SELECT|INSERT|UPDATE|DELETE" .
Finding Config References
Environment variables:
rg -n --glob "**/*.js" "process\\.env\\.|os\\.getenv\\(|getenv\\(" .
Config objects:
rg -n -i -C 1 "config\\." .
Smart-Case Matching
Use rg -S for smart-case matching:
rg -S "todo"matchesTODO,Todo, andtodorg -S "TODO"matchesTODOonly
Use rg -s when you always need case-sensitive matching:
rg -n -s "ERROR" src
Performance Tips
-
Use specific globs instead of searching all files:
rg -n --glob "src/**/*.rs" "fn deploy" . -
Use type filters for language filtering:
rg -n -t python "class MyClass" . -
Respect ignore files by default:
- Skips
node_modules,.git, and build artefacts automatically - Use
--no-ignoreonly when you need ignored directories
- Skips
-
Limit nearby lines in large searches:
rg -n "needle" src -
Use literal matching when searching exact strings:
rg -n -F "const.ERROR_MSG" src
Advanced Examples
Refactoring Scenario: Update all imports
rg -l --glob "src/**/*.ts" "^import.*from.*old-module" .
Returns all files importing the old module.
Finding Unused Exports
rg -n --glob "src/**/*.ts" "^export.*const|^export.*function" .
Auditing Security Concerns
rg -n -C 2 --glob "**/*.ts" "eval\\(|exec\\(|innerHTML|dangerouslySetInnerHTML" .
Finding Configuration Issues
rg -n -i -C 1 "hardcoded.*password|api.*key.*=|token.*=" .
Comparison with ast-grep
| Feature | rg | ast-grep |
|---|---|---|
| Speed | Very fast | Fast |
| Pattern type | Regex and literal text | AST queries |
| File filtering | Glob, type, size | Language-aware source files |
| Language support | All text files | Supported programming languages |
| Installation | Usually pre-installed | Requires binary |
| Learning curve | Regex knowledge | AST query knowledge |
| Use cases | General code search, prose, config | Syntax-aware code queries |
Advanced code_search
code_search is visible only in the advanced profile. It accepts required
query and optional path, file_types, result_types, and max_results.
Omitting result_types enables all four categories:
| Result type | Meaning |
|---|---|
definition | A recognised declaration whose name exactly matches the query. |
usage | An exact syntactic identifier outside recognised declaration names. It is not a resolved reference. |
text | A literal match in prose, configuration, comments, strings, or otherwise unclassified content. |
path | A matching existing filename or path. |
A wholly lower-case query matches without case sensitivity. A query containing
an upper-case character is case-sensitive. Query punctuation is literal. A
query containing | is split into trimmed literal alternatives (empty terms
are dropped), so tokio|async-std|runtime matches any of the three terms;
each term is escaped as a literal, so | is the only character with special
meaning.
{"query":"ToolRegistration","path":"crates/codegen/vtcode-core/src/tools","file_types":["rust"],"result_types":["definition","usage"],"max_results":20}
Each search component is bounded. truncated: true means further candidates
may exist, without claiming an exact repository-wide total. Narrow path,
file_types, or result_types in another independent call. Use
exec_command or the specialised ast-grep skill for arbitrary structural
patterns.
Troubleshooting
No Results Found
- Check regex syntax and escape special characters.
- Verify the path exists.
- Check whether files are ignored by
.gitignore; use--no-ignoreonly when that is intentional. - Add
-C 1to see nearby lines.
Too Many Results
- Add a path,
--glob, or-tfilter to narrow scope. - Pipe through
head -c 4000while exploring. - Use
rg -lwhen filenames are enough.
Slow Searches
- Add
--globto narrow scope, for example--glob "**/*.rs". - Use
-t rustor another type filter when possible. - Set
--max-filesizeto skip large files. - Keep ignore files enabled unless you need generated or vendored content.
Return Format
Text search returns normal shell output from exec_command. Use concise shell
formats for AI-facing work:
rg -n "TODO" src
rg -l "TODO" src
rg --json "TODO" src | head -c 4000
Integration with Other Tools
Inspecting Matches
- Use
rgthroughexec_command.cmdto locate text. - Use
sed,cat, or another shell command throughexec_command.cmdto inspect full context. - Use
apply_patchto make changes.
Scripted Search
# Find all matches.
results = subprocess.run(["rg", "TODO", "src"], check=False, capture_output=True, text=True)
todos = [line for line in results.stdout.splitlines() if "TODO" in line]
See Also
- AGENTS.md for system prompt integration
- Tool Registry for tool execution