Skip to content

bat & delta — Better cat & Diff for Developers

DodaTech Updated 2026-06-24 7 min read

In this tutorial, you'll learn about bat & delta. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

bat is a drop-in replacement for cat with syntax highlighting, Git integration, and line numbers. delta is a syntax-highlighting diff pager that makes Git diffs readable with side-by-side views and word-level changes.

What You'll Learn

How to use bat as a better cat with themes and paging, integrate delta with Git for beautiful diffs, configure both tools with custom themes, combine them with ripgrep and fzf for code review workflows, and use bat as a pagination tool for other commands.

Why bat and delta Matter

Reading code in the terminal is a daily task — viewing files, reviewing diffs, searching with ripgrep. Default tools are utilitarian: cat dumps raw text with no syntax highlighting, and git diff output is monochrome and hard to scan. bat adds colorized, paginated file viewing with line numbers. delta transforms Git diffs into side-by-side comparisons with word-level highlighting, making code review faster and less error-prone. Doda Browser's code review Process uses delta as the default Git pager, reducing review time by an average of 30%.

Learning Path

flowchart LR
  A[ripgrep & fd] --> B[bat & delta
You are here] B --> C[fzf & zoxide] B --> D[Starship Prompt] style B fill:#f90,color:#fff

bat — Syntax-Highlighted cat

Installation

# macOS
brew install bat

# Ubuntu/Debian
sudo apt install bat
# On Ubuntu, the binary is batcat; create an alias:
alias bat=batcat

# Fedora
sudo dnf install bat

# Arch
sudo pacman -S bat

# Download binary
curl -LO https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_amd64.deb
sudo dpkg -i bat_0.24.0_amd64.deb

Basic Usage

# View a file with syntax highlighting
bat main.py
bat index.js
bat Dockerfile

# Read from stdin (pipe to bat)
echo '{"name": "Alice"}' | bat -l json
curl -s https://api.github.com | bat -l json

# Concatenate multiple files
bat file1.py file2.py > combined.py

# Show non-printable characters
bat -A binaryfile

# Show all supported languages
bat --list-languages

Expected output:

$ bat main.py
───────┬────────────────────────────────────────────────────────
       │ File: main.py
       │ Size: 234 B
───────┼────────────────────────────────────────────────────────
   1   │ import sys
   2   │
   3   │ def main():
   4   │     name = sys.argv[1] if len(sys.argv) > 1 else "world"
   5   │     print(f"Hello, {name}!")
   6   │
   7   │ if __name__ == "__main__":
   8   │     main()
───────┴────────────────────────────────────────────────────────

Themes

# List available themes
bat --list-themes

# Preview a file with a specific theme
bat --theme="Dracula" main.py
bat --theme="Monokai Extended" main.py

# Set default theme
export BAT_THEME="Dracula"
# Add to ~/.zshrc or ~/.bashrc

Using bat as a Pager

# Set bat as the default pager for man pages
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANROFFOPT="-c"

# Use bat with ripgrep for previews
rg "function" --context 3 | bat -l js

# Pipe help output to bat
git diff --help | bat -l man

Git Integration

bat shows Git modifications in the file header:

bat README.md

For tracked files, the header shows:

───────┬───────────────────────────────────────────────
       │ File: README.md
       │ Status: M (modified)
       │ Changes: +12 -3
───────┼───────────────────────────────────────────────

Customization

# Create configuration file
bat --generate-config-file

# ~/.config/bat/config
# --theme="Monokai Extended"
# --style="numbers,changes,header"
# --paging=auto
# --map-syntax "*.test.js:JavaScript"

delta — Beautiful Diffs

Installation

# macOS
brew install git-delta

# Ubuntu/Debian
sudo apt install git-delta

# Fedora
sudo dnf install git-delta

# Arch
sudo pacman -S git-delta

# Download binary
curl -LO https://github.com/dandavison/delta/releases/download/0.17.0/delta-0.17.0-x86_64-unknown-linux-gnu.tar.gz
tar xzf delta-0.17.0-x86_64-unknown-linux-gnu.tar.gz
sudo install delta-0.17.0-x86_64-unknown-linux-gnu/delta /usr/local/bin/

Git Integration

# ~/.gitconfig
[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true
    light = false
    side-by-side = true
    line-numbers = true
    syntax-theme = Dracula
    whitespace-error-style = 22 red

[merge]
    conflictstyle = zdiff3

Side-by-Side Diffs

With side-by-side = true, git diff shows:

    src/main.py
    ─────────────────────────────────────────────────────────────
    │ modified: src/main.py
    ─────────────────────────────────────────────────────────────
    { 1: import sys                                  { 1: import sys
    { 2:                                            { 2:
    { 3: def main():                                { 3: def main():
    { 4:     name = "world"                         | 4:     name = sys.argv[1]
    { 5:     print(f"Hello, {name}!")               { 5:     print(f"Hello, {name}!")
    { 6:                                            { 6:
    { 7: if __name__ == "__main__":                 { 7: if __name__ == "__main__":
    { 8:     main()                                 { 8:     main()

Word-Level Diff Highlighting

delta highlights individual word changes within lines, not just whole lines:

# Changed line:
- const x = 10;
+ const maxItems = 10;
# "x" is highlighted in red, "maxItems" in green

Using delta with Other Tools

# Pipe any diff to delta
diff -u file1.txt file2.txt | delta

# Use with git-show
git show HEAD | delta

# Use with git-log
git log --oneline --graph --all | delta

# Use with bash diff
diff -ruN old/ new/ | delta

# JSON diff with delta
echo '{"old":{"a":1},"new":{"a":2}}' | jq -C | delta

Delta Navigation

# With navigate = true in gitconfig:
# n: next hunk
# N: previous hunk
# This works when paging through git diff output

Zero-Diff Feature

delta can show unchanged lines for context in diffs:

[delta]
    # Show unchanged lines between changed hunks
    zero-style = dim
    # Hide unchanged lines
    # zero-style = ""

Combining bat and delta

# Use bat as the file previewer for delta diffs
[delta]
    file-style = "blue"

# In Lazygit
[git]
    paging:
        pager: delta --dark --paging=never

Common Errors

1. bat Shows "Missing theme" Warning

The theme name is misspelled or not installed. List themes with bat --list-themes and use an exact match.

2. delta Not Highlighting Any Syntax

Ensure syntax-theme is set and --color-only is used for interactive.diffFilter. Check that delta is installed and in PATH.

3. "bat: command not found" on Ubuntu

Install bat directly from the .deb release. The apt package is batcat — create an alias: alias bat=batcat.

4. delta Output Is Monochrome

Set light = false in the delta config for dark terminals, or true for light terminals. The BAT_THEME environment variable must also be set.

5. Git Rebase Shows Distracting Diffs

When delta shows too much context during rebase, narrow it: git config delta.side-by-side false temporarily, or use git diff --no-pager.

6. bat Ignores BAT_THEME in Scripts

Non-interactive shells may not source your shell config. Export BAT_THEME in ~/.profile instead of ~/.zshrc.

7. delta Slows Down on Large Diffs

delta processes entire diffs. For massive commits (thousands of files), use git diff --no-pager or pipe through head.

Practice Questions

1. How do you view a file with bat using the Dracula theme? bat --theme="Dracula" filename or set export BAT_THEME=Dracula in your shell config.

2. What Git configuration makes delta the default diff pager? Add [core] pager = delta to .gitconfig. Also set [interactive] diffFilter = delta --color-only.

3. How does delta show word-level changes? delta automatically highlights inserted text in green and deleted text in red within lines, not just the entire line.

4. How do you use bat as a pager for man pages? Set export MANPAGER="sh -c 'col -bx | bat -l man -p'" in your shell config.

5. What flag shows non-printable characters in bat? -A or --show-all — useful for debugging whitespace issues in files.

Challenge: Configure bat and delta with matching themes (Dracula). Set delta as the default Git pager with side-by-side mode enabled. Create a script that: (1) generates diffs between two branches, (2) pipes them through delta for human-readable output, (3) uses bat to preview each changed file with Git status in the header, (4) outputs the result to a reviewable Markdown file. Test on a real project with at least 10 changed files.

Do bat and delta replace cat and diff completely?

For daily development, yes. For scripting and automation, cat is more reliable (no paging or color handling). delta replaces git diff but not diff for machine Parsing.

Can I use delta without Git?

Yes — diff -u file1 file2 | delta works with any diff output.

Does bat support all programming languages?

bat uses syntect which supports hundreds of languages. Run bat --list-languages to see all supported syntaxes.

How do I disable paging in bat?

Use -P or --paging=never, or pipe to another command: bat --paging=never file.

Can I customize delta's color scheme?

Yes — delta supports 16+ built-in themes and lets you customize individual colors using the plus-color, minus-color, and syntax-theme options.

What's Next

fzf & zoxide — Fuzzy Finder & Directory Jump
Starship Prompt — Custom Shell Prompt
Lazygit — Terminal Git UI Guide

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Updated 2026-06-24.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro