TL;DR — Quick Summary

bat is a cat replacement with syntax highlighting for 200+ languages, Git change markers, line numbers, and automatic paging. The cat you always wanted.

bat makes viewing files a pleasure. Syntax highlighting, line numbers, and Git changes — all automatic when you open any file.

Installation

# macOS
brew install bat

# Arch Linux
sudo pacman -S bat

# Ubuntu/Debian (note: binary may be called batcat)
sudo apt install bat
# ln -s /usr/bin/batcat ~/.local/bin/bat

# Cargo
cargo install bat --locked

Usage

# View a file with syntax highlighting
bat src/main.rs
bat package.json
bat Dockerfile

# Multiple files
bat src/*.ts

# Show specific lines
bat --line-range 10:20 src/main.rs

# Plain mode (no decorations)
bat -p file.txt

# Show all (no paging)
bat --paging=never file.txt

# Show non-printable characters
bat -A file.txt

# Force language detection
bat --language=sql query.txt

# List available themes
bat --list-themes

# Set theme
export BAT_THEME="Dracula"

Integration

# Alias cat (safe — bat detects pipes)
alias cat='bat'

# fzf preview
fzf --preview 'bat --color=always --line-range :500 {}'

# Man page viewer
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANROFFOPT="-c"

# Git diff (with Delta)
# In .gitconfig:
# [core]
#   pager = delta
# Delta uses bat for syntax highlighting

Comparison

Featurebatcatlesshighlight
Syntax highlighting200+ languagesNoNoYes
Line numbersYes-n flag-N flagYes
Git markersYesNoNoNo
PagingAutoNoManualNo
Pipe-safeYesYesN/AYes
SpeedFastFastestFastSlow

Summary

  • bat is cat with syntax highlighting for 200+ languages, automatic
  • Line numbers, Git change markers, and decorations built-in
  • Auto-detects pipes — safe to alias cat=bat
  • Integrates with fzf, man pages, and Delta for git diffs
  • Customizable themes (Dracula, One Dark, Nord, etc.)