Hyperlinks¶
Modern terminals support clickable hyperlinks through OSC 8 escape sequences. ripgrep can generate these hyperlinks for search results, making it easy to jump directly to matches in your editor.
Overview¶
Hyperlink support allows terminal emulators to display clickable file paths that open directly in your preferred editor or application. This is particularly useful when: - Reviewing search results interactively - Working in a terminal-heavy workflow - Quickly navigating between files - Integrating with IDE-like terminal experiences
flowchart TD
A[ripgrep Output] --> B["OSC 8 Escape Sequence"]
B --> C[Terminal Emulator]
C --> D{User Clicks Link?}
D -->|Yes| E[Extract URL]
D -->|No| End[Display Only]
E --> F{URL Scheme Registered?}
F -->|Yes| G[Open in Editor or Application]
F -->|No| H[Error: No Handler]
G --> End
H --> End
style A fill:#e1f5ff
style C fill:#fff3e0
style G fill:#e8f5e9
style H fill:#ffebee
Figure: How terminal hyperlinks work - from ripgrep output to editor integration.
Enabling Hyperlinks¶
Use the --hyperlink-format flag to enable hyperlink generation:
Test Your Terminal First
Before configuring hyperlinks globally, verify your terminal supports OSC 8 sequences:
If "This is a link" appears clickable, your terminal supports hyperlinks.Built-in Aliases¶
Instead of writing full hyperlink format strings, ripgrep provides convenient built-in aliases for common editors and schemes:
| Alias | Expands to |
|---|---|
default |
Platform-aware file:// scheme (see below) |
file |
file://{host}{path} |
vscode |
vscode://file/{path}:{line}:{column} |
vscode-insiders |
vscode-insiders://file/{path}:{line}:{column} |
vscodium |
vscodium://file/{path}:{line}:{column} |
cursor |
cursor://file/{path}:{line}:{column} |
macvim |
mvim://open?url=file://{path}&line={line}&column={column} |
textmate |
txmt://open?url=file://{path}&line={line}&column={column} |
kitty |
file://{host}{path}#{line} |
grep+ |
grep+://{path}:{line} |
none |
Explicitly disable hyperlinks |
The default alias is platform-aware and expands differently per platform:
- Unix/Linux/macOS: file://{host}{path} (includes hostname)
- Windows: file://{path} (omits hostname for compatibility)
The default alias follows RFC 8089 file:// URI specification and is the recommended choice for general use.
Platform-Aware Behavior
The default alias automatically adapts to your platform. On Unix/Linux/macOS it includes the hostname for network compatibility. On Windows it omits the hostname to prevent compatibility issues with some applications.
The file alias always includes the hostname regardless of platform. Use default for cross-platform scripts and configurations.
The none alias can be used to explicitly disable hyperlinks, which is useful for overriding config file settings:
Hyperlink Formats¶
You can use built-in aliases or create custom hyperlink formats using a template syntax:
# Using a built-in alias
rg --hyperlink-format vscode pattern
# Using default platform-aware format
rg --hyperlink-format default pattern
# Custom format with line number
rg --hyperlink-format 'file://{path}:{line}' pattern
Format Variables¶
Available variables for hyperlink templates:
| Variable | Description | Auto-populated |
|---|---|---|
{path} |
Absolute or relative file path | Required in format |
{line} |
Line number of the match | From search result |
{column} |
Column number of the match | From search result |
{host} |
Machine hostname | From system hostname |
{wslprefix} |
WSL distro prefix (e.g., wsl$/Ubuntu) |
From WSL_DISTRO_NAME env var (Windows/WSL only) |
Variable Usage Notes
{host}is useful for network file shares or remote development environments{wslprefix}enables proper file:// URLs when working in Windows Subsystem for Linux{path}is required in every hyperlink format{column}requires{line}to also be present in the format
WSL Users
If you're using ripgrep inside WSL but clicking hyperlinks from Windows Terminal, include {wslprefix} in your format:
Terminal Support¶
Not all terminals support OSC 8 hyperlinks. Compatible terminals include:
Well Supported¶
- iTerm2 (macOS): Full support
- Windows Terminal: Full support
- WezTerm: Full support
- Hyper: Full support
- Kitty: Full support
Partial Support¶
- GNOME Terminal: Supported in recent versions
- Konsole: Supported in recent versions
- Alacritty: Support in progress
Not Supported¶
- Traditional Terminal.app (macOS): No support
- Basic xterm: No support
- Most older terminal emulators: No support
URL Schemes¶
Different URL schemes enable different behaviors:
File Scheme¶
Open files in default application:
# Using the built-in 'file' alias
rg --hyperlink-format file pattern
# Equivalent custom format
rg --hyperlink-format 'file://{path}' pattern
Editor Schemes¶
Open files directly in specific editors using built-in aliases:
# VS Code
rg --hyperlink-format vscode pattern
# VS Code Insiders
rg --hyperlink-format vscode-insiders pattern
# VSCodium
rg --hyperlink-format vscodium pattern
# Cursor
rg --hyperlink-format cursor pattern
# MacVim
rg --hyperlink-format macvim pattern
# TextMate
rg --hyperlink-format textmate pattern
# Kitty terminal editor integration
rg --hyperlink-format kitty pattern
# grep+ macOS application
rg --hyperlink-format grep+ pattern
Custom Editor Integration¶
For editors not included in the built-in aliases, you can create custom hyperlink formats:
Community Formats - Registration Required
These are community-suggested formats that require custom URL scheme handlers to be registered with your OS. They are not built into ripgrep and may not work without additional setup.
# IntelliJ/PyCharm/WebStorm (community format)
rg --hyperlink-format 'idea://open?file={path}&line={line}' pattern
# Sublime Text (community format)
rg --hyperlink-format 'subl://open?url=file://{path}&line={line}' pattern
# Neovim remote (community format)
rg --hyperlink-format 'nvim://edit/{path}:+{line}' pattern
See the URL Scheme Registration section below for platform-specific setup instructions.
Configuration¶
Set up hyperlinks globally via your ripgrep config file:
# ~/.ripgreprc or $RIPGREP_CONFIG_PATH
# Using a built-in alias (recommended)
--hyperlink-format=vscode
# Or using a custom format
--hyperlink-format=vscode://file/{path}:{line}:{column}
Examples¶
Quick Start: VS Code Integration
The fastest way to get started is using a built-in alias:
Click on any result to open the file at the exact line in VS Code. This is equivalent to the full formatvscode://file/{path}:{line}:{column} but more concise.
Example 1: VS Code Integration with Built-in Alias¶
Click on any result to open the file at the exact line in VS Code. This is equivalent to the full format vscode://file/{path}:{line}:{column} but more concise.
Example 2: Using the Default Platform-Aware Format¶
# Use default format (includes hostname on Unix, omits on Windows)
rg --hyperlink-format default pattern
On Unix/Linux/macOS, this expands to file://{host}{path}. On Windows, it expands to file://{path}.
Example 3: Kitty Terminal Editor Integration¶
# Open results using kitty's file:// handler (with line number fragment)
rg --hyperlink-format kitty pattern
Example 4: Disabling Hyperlinks¶
Example 5: Custom Editor Integration¶
# Neovim remote integration (custom format)
rg --hyperlink-format 'nvim://edit/{path}:+{line}' pattern
Note: Custom formats require URL scheme registration with your operating system.
Best Practices¶
Configuration Recommendations
- Test first: Verify terminal compatibility before global configuration
- Use built-in aliases: Prefer
vscodeover customvscode://...formats - Start with default: Use
--hyperlink-format defaultfor cross-platform compatibility - Configure globally: Add to
~/.ripgreprcfor consistent behavior - Include position: Use formats with
{line}and{column}for precise navigation
- Test hyperlinks in your terminal before relying on them
- Configure your terminal to handle custom URL schemes
- Use absolute paths for hyperlinks when working with remote files
- Include line and column numbers for precise navigation
- Set up config file for consistent hyperlink behavior
- Verify URL scheme registration for your editor
Troubleshooting¶
Hyperlinks Not Clickable¶
Possible causes: 1. Terminal doesn't support OSC 8 sequences 2. Hyperlink format is invalid 3. URL scheme not registered with OS 4. Terminal hyperlink feature disabled
Solutions:
# Test if terminal supports hyperlinks
printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'
# Check ripgrep version (hyperlinks require recent version)
rg --version
# Verify URL scheme registration
# macOS: Check in /System/Library/CoreServices/SystemVersion.plist
# Linux: Check .desktop files in ~/.local/share/applications/
Wrong Application Opens¶
The URL scheme might be registered to a different application:
Path Resolution Issues¶
Use absolute paths to avoid ambiguity:
Advanced Usage¶
Escaping Special Characters¶
To include literal braces in your hyperlink format, use double braces:
Literal Braces in Formats
# Include literal { and } characters in format
rg --hyperlink-format 'myscheme://{{literal}}/{path}' pattern
# This expands to: myscheme://{literal}/path/to/file
Use {{ for a literal { and }} for a literal }.
Format Validation Requirements¶
Hyperlink formats must meet these validation constraints:
- Must contain at least a
{path}variable - If
{column}is used,{line}must also be present - Format must start with a valid URL scheme (alphanumeric characters,
+,-, or.)
Valid Format
Invalid Format Examples
Conditional Hyperlinks¶
Only use hyperlinks when output is to terminal:
Custom Link Processing¶
Process hyperlinks with other tools:
# Extract paths from hyperlinks
rg --hyperlink-format file pattern | sed 's/.*file:\/\/\([^[:space:]]*\).*/\1/'
URL Scheme Registration¶
To use custom editor hyperlink formats, you need to register URL scheme handlers with your operating system:
Method 1: Using an application's built-in registration
Most editors (VS Code, Sublime Text, etc.) automatically register their URL schemes during installation.
Method 2: Creating a custom .app bundle
For custom schemes, create an application bundle with an Info.plist that declares the URL scheme:
Security Considerations¶
URL Scheme Security
Be cautious when registering custom URL schemes:
- Validate sources: Only use hyperlink formats from trusted sources
- Review handlers: Some URL schemes can execute arbitrary commands
- Audit custom schemes: Review what custom URL handlers do before registration
- Disable in sensitive contexts: Consider
--hyperlink-format nonein security-sensitive environments
- Be cautious with hyperlink formats from untrusted sources
- Validate URL schemes before registering handlers
- Some terminals may execute arbitrary commands via URL schemes
- Consider disabling hyperlinks in security-sensitive environments
See Also¶
- Output Formats - Other output customization options
- Configuration File - Setting up persistent configuration
- Common Options - Output formatting options