Reading raw terminal output without syntax highlighting can slow down development and increase errors. By setting bat as the default pager for less, you instantly add color-coded syntax to man pages, git logs, and any command using the pager—without changing your existing workflow. This simple configuration boosts readability and reduces cognitive load during daily tasks.
Why Syntax-Highlighted Less Output Matters for Developers
Default terminal pagers like less display plain text, making code and configuration files hard to parse. Syntax highlighting visually separates keywords, strings, and structures, helping developers spot errors faster and understand complex outputs with minimal effort. For teams working across multiple languages or systems, this consistency saves minutes per file that add up to hours weekly.
Step-by-Step Guide to Configure bat as Default Pager
Step 1: Install bat
Install bat (version 0.20+) using your system’s package manager. On macOS, run brew install bat. For Ubuntu/Debian, use sudo apt install bat. Windows users can install via choco install bat or scoop install bat.
Step 2: Configure Environment Variables
Open your shell config file (~/.bashrc, ~/.zshrc, or equivalent) and add these lines:
-
export PAGER=batsets bat as the global pager for all commands that use less. -
export BAT_PAGER=lessensures bat uses less for paging, avoiding recursive loops while preserving scrolling functionality.
Apply changes immediately with source ~/.bashrc (or your shell config file).
Step 3: Test Your Setup
Run man ls or git log. You should see syntax-highlighted output with colors for keywords, comments, and file paths. For example, Python code in a man page will highlight def, class, and strings in distinct colors—making it instantly readable.
Key Benefits and Considerations
This configuration works seamlessly with most terminal emulators and shells. However, ensure your terminal supports 256-color mode by setting export TERM=xterm-256color if colors appear incorrect. While bat handles small-to-medium files efficiently, extremely large files (e.g., multi-gigabyte logs) may benefit from using less directly for faster rendering. Always test with your typical workflows to confirm compatibility.
Conclusion
Setting bat as the default pager for less is a zero-effort upgrade that dramatically improves terminal readability. By configuring just two environment variables, you gain syntax highlighting across all pager-based commands—saving time and reducing errors. Start today to transform how you interact with your terminal, and explore related tools like delta for git diffs or ripgrep for lightning-fast searches to further optimize your workflow.