Skip to content
Alexey Kurin edited this page Oct 17, 2024 · 12 revisions

This page lists some ranger goodies to be used with lf.

Transition guide for ranger users

For users who are already used to ranger as a file manager, moving to lf means less default features and a slightly different behavior. This page is supposed to include a collection of configuration steps needed to make lf behave more like rangers defaults in order to make the transition easier.

File Previews (Scope)

By default, lf will only preview text files. To enable previews for other file types, we can use rangers scope.sh file for lf to some extent. First, create a wrapper script ~/.config/lf/scope-lf-wrapper.sh as follows:

#!/bin/sh
"$HOME/.config/ranger/scope.sh" "${1}" "${2}" "${3}" "" "" || true

Then set previewer option and pager mapping in lfrc to use this script as follows:

set previewer ~/.config/lf/scope-lf-wrapper.sh
map i $LESSOPEN='| ~/.config/lf/scope-lf-wrapper.sh %s' less -R $f

Note, ranger uses return codes for different semantics so we append || true to enable caching in lf. Also, arguments ${4} and ${5} are used for image previews in ranger which does not work directly in lf so they are left empty. See also Previews wiki page for image previews in lf.

File opener (Rifle)

Ranger has a rifle.py file executor/opener, which can simply be used by lf instead of the default mimeopen command.

The easiest way to change the file opener in lf is to set the environment variable $OPENER in your shell configuration (e.g. ~/.bashrc or ~/.zshrc):

export OPENER='rifle'

Alternatively you can configure the file opener in lf by changing the open command in your lfrc file:

cmd open $set -f; rifle -p 0 "$fx"

You can also list all possible ways to open a file with a command/mapping as follows:

cmd open-with ${{
    clear
    set -f
    rifle -l $fx | sed -e "s/:[a-Z]*:[a-Z]*:/ \| /"
    read -p "open with: " method
    rifle -p $method $fx
}}
map r open-with

Note that these examples assume you are using a posix compatible shell (e.g. set shell sh) and you have the appropriate settings to handle filenames without quoting in your configuration file (e.g. set ifs "\n"). Also note that the example mapping overwrites the default r binding for rename command in lf.

Deleting files / Trash

By default, the delete command is not enabled in lf, so we need to add it if we want to remove files or move it to the trash. One of the cool projects I found while experimenting with lf was trash-cli and how easy it integrates into lf:

cmd trash %trash-put "$fx"
map D trash

Automatic refresh

To enable the same automatic file updates that we are used from ranger, lf offers the period option to poll the directory status every x seconds:

set period 1

File and directory size

Enable file and directory information like rangers defaults:

set info size
set dircounts

Add directory with f7

map <f-7> push :mkdir<space>""<c-b>

leave some space at the top and the bottom of the screen

set scrolloff 10

clear mark from files after pasting

In lf, files that have been copied are marked and stay marked after being pasted/moved. This changed the behavior back to rangers default:

map p : paste; clear

colors

Lf uses GNU dircolors defaults to display different file types. This can be changed by adapting the colors file in the lf configuration directory. Add this colors files to your lf config directory (~/.config/lf/colors) to change the colors to rangers defaults.