Introduction

Although I’m using KDE on a daily basis, I’ve used tiling window managers (i3, bspwm) in the past, which kind of goes hand in hand with CLI software, I still use some of the CLI applications I used back then. One of those programs is vifm, which is a great file manager which is optimized for keyboard use (duh). It uses vim keybindings and supports scripting, it’s very comfortable and customizable. The feature I like the most by far is the bulk rename feature: You can select a bunch of files, press “cw” and you can edit the filenames with vim, or another powerful editor of your choice.

There’s one thing that vifm, or rather w3m can’t do well (yet): Image Previews. This has always been a problem with CLI file browsers and the solutions were mostly very “hackish”, especially when looking at w3m. Luckily there is an alternative: Überzug. w3m may work okayish with urxvt, but it can be an horrendous experience in other terminals like termite or st. Überzug luckily doesn’t have this problem and works fairly well with most terminals. Another benefit is the lack of flickering, which is a common occurrence with w3m.

This tutorial is based on the answer of the user seebye in this Reddit thread.

Installation

Requirements

  • package vifm installed
  • (pip) package ueberzug installed

First of all you need to open your vifmrc file located at ~/.config/vifm/ and find the line where the “fileviewer” of images is defined. All you need to do is replace it with the following:

fileviewer *.jpg,*.jpeg,*.png
           \ vifmimg draw %px %py %pw %ph %c
           \ %pc
           \ vifmimg clear 

You probably noticed that a program / script called vifmimg is being executed. It doesn’t exist yet, so we need to create it. Go to your ~/.config/vifm/scripts/ folder (if it doesn’t exist just create it) and create a new script called vifmimg with the following content:

#!/usr/bin/env bash
readonly ID_PREVIEW="preview"

if [ -e "$FIFO_UEBERZUG" ]; then
    if [[ "$1" == "draw" ]]; then
        declare -p -A cmd=([action]=add [identifier]="$ID_PREVIEW"
                           [x]="$2" [y]="$3" [width]="$4" [height]="$5" \
                           [path]="${PWD}/$6") \
            > "$FIFO_UEBERZUG"
    else
        declare -p -A cmd=([action]=remove [identifier]="$ID_PREVIEW") \
            > "$FIFO_UEBERZUG"
    fi
fi

Now we’re almost done, the only thing you need to do now is to create a startup script for vifm, I recommend to create one in your /usr/local/bin/ directory for quick access. I called mine vifm-img. You need to input the following content:

#!/usr/bin/env bash
export FIFO_UEBERZUG="/tmp/vifm-ueberzug-${PPID}"

function cleanup {
    rm "$FIFO_UEBERZUG" 2>/dev/null
    pkill -P $$ 2>/dev/null
}

rm "$FIFO_UEBERZUG" 2>/dev/null
mkfifo "$FIFO_UEBERZUG"
trap cleanup EXIT
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser bash &

vifm
cleanup

Now alias vifm to vifm-img and you’re good to go! Enjoy your image previews!

End Result

image