Install
Install the latest published binary.
macOS / Linux / Android / Termux:
|
Windows:
irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.ps1 | iex
npm:
Homebrew:
Install the leaf formula from Homebrew:
Cargo:
Install the leaf crate from crates.io:
ArchLinux (AUR):
Use an AUR helper, such as yay:
Verify the installation:
Update
Update an existing installation to the latest published release.
Self:
leaf --update downloads the matching published asset, verifies it against the published checksums.txt SHA256, and then installs it.
On Windows, if replacing the running .exe is blocked by the OS, rerun the PowerShell installer from the install section.
npm:
Homebrew:
Cargo:
Usage
# Open a Markdown file
# Watch mode — reloads automatically on save
# Open the fuzzy Markdown picker
# Open the classic directory browser picker
# Open the fuzzy Markdown picker, then watch the selected file
# Open the classic directory browser picker, then watch the selected file
# Open a dash-prefixed filename
# Pick a color theme
# Set the external editor
# Cap the content width (min: 20)
# Stream Markdown from another CLI tool
|
# Preview a local file through stdin
|
Inline Mode
Render Markdown directly to stdout without the interactive TUI:
# Render to terminal with colors
# Force plain text, no ANSI codes (no colors)
# Force ANSI colors even when piping
# Set a specific width
# Pipe from stdin
|
# Use as a fzf preview
Shell Completions
Enable Tab completion for all arguments:
Supports bash, zsh, fish, and PowerShell. Restart your shell to activate.
Vim Integration
Add the following to your ~/.vimrc to preview the current Markdown file in a vertical split:
" Preview the current Markdown file in a vertical split using leaf
nnoremap <Leader>md :vertical botright terminal leaf -w %<CR>
Once added, use \md to open a live preview. To switch focus back to the Markdown buffer, press Ctrl+w,h.
Configuration
Set default values for theme, editor, watch mode and extra file types via config.toml:
This opens the configuration file in your editor. If the file does not exist yet, leaf creates it with documented defaults.
= "ocean" # arctic, forest, ocean, solarized-dark, or a custom theme file
= "nano" # any editor in PATH
= false # auto-reload when opening a file
= 80 # maximum content width (min: 20, default: terminal width)
= ["txt", "rs"] # extra file types shown in the picker
= true # show line numbers inside fenced code blocks
= -1 # terminal tab title truncation (min: 20, -1: no truncation)
To reset the configuration to defaults:
All settings are optional. CLI arguments always take priority. See config.toml for details.
Open in Editor
Press Ctrl+E to open the current file in the configured editor.
Use {$line} in editor to open at the line currently visible in leaf:
= 'nano +{$line}'
= 'nvim +{$line} +"normal! zz"'
For further customization, {$path} is also available for the file path:
= 'code -g {$path}:{$line}'
Without {$line}, the editor opens at the top of the file.
Extra Files
Non-Markdown files can be listed in the file picker by adding their extensions to config.toml:
= ["txt", "csv", "rs", "java", "json", "yaml"]
Code files get syntax highlighting; text files are rendered as plain Markdown.
Any file can also be opened directly from the command line, regardless of the extras setting:
Browse and preview code files with fzf:
|
Custom Themes
Create a .toml file that inherits from a built-in theme and overrides specific colors:
= "/path/to/custom-theme.toml"
Relative paths are resolved from the config file directory.
# custom-theme.toml
= "ocean"
= "base16-ocean.dark"
[]
= "#282828"
= "#fe8019"
[]
= "#ebdbb2"
= "#fabd2f"
See gruvbox.toml for a complete example with all available color keys.
Keybindings
| Key | Action | Key | Action |
|---|---|---|---|
j / ↓ |
Scroll down | ? |
Show help popup |
k / ↑ |
Scroll up | t |
Toggle TOC sidebar |
d / PgDn |
Page down (20 lines) | p |
Show file path |
u / PgUp |
Page up (20 lines) | Shift+L |
Toggle line numbers |
g / Home |
Top | Shift+T |
Open theme picker |
G / End |
Bottom | Shift+E |
Open editor picker |
1-9 / 0+1-9 |
Jump / reverse jump (TOC) | Shift+P |
Open file browser |
J/K / U/D |
Navigate TOC | Shift+M |
Toggle mouse capture |
y/Y / c/C |
Focus code block | Ctrl+P |
Open fuzzy picker |
Ctrl+L |
Go to line | Ctrl+E |
Open in editor |
Ctrl+F / / |
Find | Ctrl+Click |
Open link |
n / N |
Next / prev match | Double-Click (link) |
Copy link |
w |
Toggle watch mode | Double-Click (code) |
Copy code block |
r |
Force reload (watch mode) | Shift+Drag |
Select text |
q |
Quit | Option+Drag |
Select text (iTerm2) |
Features
- Live preview : Watch mode with automatic reload and visual feedback.
- File picker : Fuzzy Markdown picker, directory browser, and watch after selection.
- Editor integration : Open the current file in your preferred editor.
- Frontmatter support : YAML frontmatter rendered as a table (horizontal or vertical based on key count).
- Rich Markdown rendering : Tables, lists, blockquotes, rules, bold, italic, and strikethrough.
- GitHub extras : Alert callouts, task list checkboxes, and
==mark==text highlighting. - Extra file types : Open any file; code files get syntax highlighting, text files render as Markdown.
- Syntax highlighting : Common aliases like
py,cpp,json,toml,ps1,dockerfile. - Line numbers : Toggle display with
Shift+L, jump to a line withCtrl+L. - LaTeX support : Inline, block, and
latex/texcode blocks rendered as formulas. - Mermaid diagrams :
mermaidcode blocks rendered as ASCII diagrams. - Clickable links :
Ctrl+Clickto open, double-click to copy, hover feedback. - Code block interactions : Focus and copy with
y/Y/c/C, or double-click on a block. - Mouse capture :
Shift+Mto toggle mouse capture and let the terminal handle selection. - Navigation : TOC sidebar, active section tracking, heading jumps, and search.
- Terminal UX : Theme picker, help popup, file path popup, mouse and keyboard support.
- Custom themes : TOML theme files inheriting from built-in presets with color overrides.
- Inline mode : Render to stdout with
--inlinefor pipes and fzf previews. - Shell completions : Tab completion for bash, zsh, fish, and PowerShell via
leaf --auto-complete. - CLI friendly : stdin support and
leaf --updatewith SHA256 verification.
Typical AI Workflow
# Terminal 1: generate the file
# Terminal 2: live watch
Troubleshooting
Windows: missing Visual C++ runtime
If leaf.exe does not start on Windows or reports a missing MSVC runtime, install the latest supported Microsoft Visual C++ Redistributable from Microsoft Learn:
Direct download for the latest supported X64 Microsoft Visual C++ Redistributable:
For leaf-windows-x86_64.exe, the relevant package is the latest supported X64 Visual C++ v14 Redistributable.
Windows: update or file replacement error
If leaf --update fails on Windows with an error about replacing, renaming, or writing leaf.exe, the running executable was likely locked by the OS.
Close any terminal session still running leaf, then rerun the PowerShell installer from the install section:
irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.ps1 | iex
Windows: auto-complete execution policy error
If PowerShell reports that running scripts is disabled on this system after leaf --auto-complete, allow local scripts and restart PowerShell:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Uninstall
macOS / Linux / Android / Termux:
Windows:
Remove-Item "$env:LOCALAPPDATA\Programs\leaf\leaf.exe" -Force
npm:
Homebrew:
Cargo:
Contributors
Thanks to all contributors.
Support
Contributions are welcome. Feel free to open an issue or submit a pull request.
See the CONTRIBUTING.md file for details.
If you like leaf, consider giving the project a star ⭐
License
This project is licensed under the MIT License.
See the LICENSE file for details.