终端 Markdown 预览器 — 类似 GUI 的体验。
Terminal Markdown previewer — GUI-like experience.
See more screenshots in the features demo
Install the latest published binary.
macOS / Linux / Android / Termux
curl -fsSL https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.sh | shWindows
irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/install.ps1 | iexnpm
Install the package from npmjs.com:
npm install -g @rivolink/leafHomebrew
Install the formula from brew.sh:
brew install leaf-markdown-viewerCargo
Install the crate from crates.io:
cargo install leaf-markdown-viewerScoop (Windows)
Install the app from scoop.sh:
scoop install leaf-markdown-viewerArchLinux (AUR)
Install the package from archlinux.org, use an AUR helper such as yay:
yay -S leaf-markdown-viewerVerify the installation
leaf --versionUpdate an existing installation to the latest published release.
Self
leaf --updateleaf --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
npm update -g @rivolink/leafHomebrew
brew upgrade leaf-markdown-viewerCargo
cargo install leaf-markdown-viewer --forceScoop (Windows)
scoop update leaf-markdown-viewer…Render Markdown directly to stdout without the interactive TUI:
# Render to terminal with colors
leaf --inline README.md
# Force plain text, no ANSI codes (no colors)
leaf --inline plain README.md
# Force ANSI colors even when piping
leaf --inline ansi README.md
# Set a specific width
leaf --inline 60 README.md
leaf --inline ansi:60 README.md
# Pipe from stdin
cat README.md | leaf --inline
# Use as a fzf preview
fzf --preview 'leaf --inline ansi {}'
fzf --preview 'leaf --inline ansi:$FZF_PREVIEW_COLUMNS {}'Enable Tab completion for all arguments:
leaf --auto-completeSupports bash, zsh, fish, Nushell, and PowerShell. Restart your shell to activate.
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.
Set default values for theme, editor, watch mode, extra file types, and more via config.toml:
leaf --configThis opens the configuration file in your editor. If the file does not exist yet, leaf creates it with documented defaults.
…To reset the configuration to defaults:
leaf --config resetTo remove the configuration directory and all its contents:
leaf --config removeAll settings are optional. CLI arguments always take priority. See config.toml for details.
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:
editor = 'nano +{$line}'
editor = 'nvim +{$line} +"normal! zz"'For further customization, {$path} is also available for the file path:
editor = 'code -g {$path}:{$line}'Without {$line}, the editor opens at the top of the file.
Non-Markdown files can be listed in the file picker by adding their extensions to config.toml:
extras = ["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:
leaf main.rsBrowse and preview code files with fzf:
find . -name '*.rs' | fzf --preview 'leaf --inline ansi {}'Create a .toml file that inherits from a built-in theme and overrides specific colors:
theme = "/path/to/custom-theme.toml"Relative paths are resolved from the config file directory.
# custom-theme.toml
base = "ocean"
syntax = "base16-ocean.dark"
[ui]
content_bg = "#282828"
toc_accent = "#fe8019"
[markdown]
text = "#ebdbb2"
heading_1 = "#fabd2f"See gruvbox.toml for a complete example with all available color keys.
| Key | Action | Key | Action |
|---|---|---|---|
j / ↓ |
Scroll down | ? |
Show help popup |
k / ↑ |
Scroll up | p |
Show file path |
d / PgDn |
Page down (20 lines) | Shift+L |
Toggle line numbers |
u / PgUp |
Page up (20 lines) | Shift+T |
Open theme picker |
g / Home |
Top | Shift+E |
Open editor picker |
G / End |
Bottom | Shift+P |
Open file browser |
1-9 / 0+1-9 |
Jump / reverse jump (TOC) | Shift+M |
Toggle mouse capture |
J/K / U/D |
Navigate TOC | Ctrl+P |
Open fuzzy picker |
y/Y / c/C |
Focus code block | Ctrl+H |
Open file history 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 |
t |
Toggle TOC sidebar | Option+Drag |
Select text (iTerm2) |
q |
Quit |
history.toml, picker via Ctrl+H or leaf --history.==mark== text highlighting.py, cpp, json, toml, ps1, dockerfile.Shift+L, jump to a line with Ctrl+L or :.latex / tex code blocks rendered as formulas.mermaid code blocks rendered as ASCII diagrams.Ctrl+Click to open, double-click to copy, hover feedback.y/Y / c/C, or double-click on a block.Shift+M to toggle mouse capture and let the terminal handle selection.--inline for pipes and fzf previews.leaf --auto-complete.leaf --update with SHA256 verification.# Terminal 1: generate the file
aichat "..." > notes.md
# Terminal 2: live watch
leaf --watch notes.mdIf 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.
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 | iexIf PowerShell reports that running scripts is disabled on this system after leaf --auto-complete, allow local scripts and restart PowerShell:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUserThe uninstall script removes the leaf configuration, shell auto-completion, and binary. It is interactive, so download first and run locally.
macOS / Linux / Android / Termux
# Download
curl -fsSL https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/uninstall.sh -o uninstall.sh
# Run
sh uninstall.shWindows
# Download
irm https://raw.githubusercontent.com/RivoLink/leaf/main/scripts/uninstall.ps1 -OutFile uninstall.ps1
# Run
powershell -ExecutionPolicy Bypass -File .\\uninstall.ps1npm
leaf --config remove
leaf --auto-complete remove
npm uninstall -g @rivolink/leafHomebrew
leaf --config remove
leaf --auto-complete remove
brew uninstall leaf-markdown-viewerCargo
leaf --config remove
leaf --auto-complete remove
cargo uninstall leaf-markdown-viewerScoop (Windows)
leaf --config remove
leaf --auto-complete remove
scoop uninstall leaf-markdown-viewerThanks to all contributors.
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 ⭐
This project is licensed under the MIT License.
See the LICENSE file for details.
暂无开放 Issues,或尚未同步最近议题。