bat cat with syntax highlighting
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
bat <file>
bat <a> <b>
bat -n <file>
bat -p <file>
bat -l <lang>
bat -r 10:20 <file>
bat -A <file>
bat --list-themes
Concepts
- Input files or stdin
- Highlight theme + language
- Decorations numbers, grid, changes
- Pager less, only if long
Viewing
bat <file>
bat <a> <b>
<cmd> | bat -l <lang>
bat -r <start>:<end> <file>
bat -r :<n> <file>
bat -r <n>: <file>
bat -r <n>:+<m> <file>
bat -r <n>::<c> <file>
bat -A <file>
bat -l <lang> <file>
bat --list-languages
bat --map-syntax '<glob>:<lang>'
bat --tabs <n>
bat --wrap never
Output style
bat -p <file>
bat -pp <file>
bat -n <file>
bat --style numbers,changes <file>
bat --style=-grid,+snip <file>
bat --style full <file>
bat --color always
bat --force-colorization
| Name | Draws |
|---|---|
numbers |
line numbers |
changes |
git add/modify marks |
header |
file name header |
grid |
borders |
rule |
line between files |
snip |
cut marks for ranges |
Paging
bat --paging never <file>
bat -P <file>
bat --paging always <file>
bat --pager "less -RFK"
bat --pager builtin
export BAT_PAGER="less -RFK"
alias cat='bat --paging=never'
tail -f <log> | bat --paging=never -l log
Themes
bat --list-themes
bat --theme <name> <file>
export BAT_THEME="<name>"
bat --theme auto:system
bat --theme-dark <name> --theme-light
<name>
bat --list-themes | fzf --preview="bat --theme={}
--color=always <file>"
Config and cache
bat --generate-config-file
bat --config-file
bat --config-dir
export BAT_CONFIG_PATH="<file>"
export BAT_STYLE="numbers,changes"
bat cache --build
bat cache --clear
With other tools
git diff --name-only --relative --diff-filter=d -z | xargs
-0 bat --diff
git show <rev>:<path> | bat -l
<lang>
export MANPAGER="bat -plman"
fzf --preview "bat --color=always --style=numbers
--line-range=:500 {}"
fd <pattern> -X bat
find <path> -name '<glob>' -exec bat {}
+
<cmd> --help | bat -plhelp
bat --diff <file>
Recipes
fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}' \ --bind 'enter:become(${EDITOR:-vi} {})'
export MANPAGER="bat -plman"man 2 selectgit --help | bat -plhelp
curl -s <url> | jq . | bat -l jsonkubectl get pod <name> -o yaml | bat -l yaml -p
git diff --name-only --relative --diff-filter=d -z \ | xargs -0 bat --diff



