Displaying Images in lf with Kitty and Tmux

Published: (January 3, 2026 at 10:45 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Overview

When using lf (the terminal file manager) with Kitty and Tmux, image preview display can leave graphical artifacts on the screen when switching from one preview to another, making the interface unreadable.

The solution relies on three elements:

  1. The redraw command in lf
  2. No external cleaner script
  3. The on-select event in lf

The key idea is to ask lf to redraw itself on each selection, which clears the terminal and ensures a clean preview display.

Configuration (lfrc)

Add the following to your ~/.config/lf/lfrc (or the appropriate lfrc location):

set previewer ~/.local/bin/lfpreview

cmd on-select &{{
  exec lf -remote 'send redraw'
}}
  • set previewer points lf to the preview script.
  • The on-select command triggers a remote redraw request each time a file is selected.

Preview Script (lfpreview)

Create the file ~/.local/bin/lfpreview with the following content and make it executable:

#!/bin/sh
draw() {
  kitten icat --stdin no --transfer-mode memory \
    --place "${w}x${h}@${x}x${y}" "$1" /dev/tty
}

file="$1"
w="$2"
h="$3"
x="$4"
y="$5"

case "$(file -Lb --mime-type "$file")" in
  image/*)
    draw "$file"
    ;;
  application/pdf)
    pdftoppm -f 1 -singlefile "$file" "/tmp/lfoutput"
    draw "/tmp/lfoutput.ppm"
    ;;
  *)
    less "$1"
    ;;
esac

exit 1   # do not cache
chmod +x ~/.local/bin/lfpreview

How it works

  • Images – displayed directly with Kitty’s icat.
  • PDFs – the first page is converted to an image using pdftoppm, then displayed.
  • Other files – opened with less.

The exit 1 at the end tells lf not to cache the preview. Without this, the refresh mechanism would reuse cached previews, and the image would not be redrawn on each selection.

Adjustments

This configuration works for the typical use case, but you may need to tweak:

  • Paths to kitten icat or pdftoppm if they differ on your system.
  • Additional MIME types in the case statement to handle other file formats.

Feel free to extend the script to suit your workflow.

Back to Blog

Related posts

Read more »

Tmux - less windows, more ⚒

I love the terminal. As a Windows user, I’ve been using wsl for more than three years. I’ve tried many terminal emulators—cmder, Fluid, and others—but nothing i...