Aller au contenu

Ranger Cheat Sheet

Overview

Ranger is a console-based file manager with vim-style keybindings. It provides a three-column view where the left column shows the parent directory, the middle column is the current directory, and the right column shows a preview of the selected file or subdirectory. Ranger aims to be visually pleasing and efficient, making file navigation fast without leaving the terminal.

Ranger is written in Python and supports file previews for text, images (in compatible terminals), PDFs, archives, and more through external tools. It features tabs, bookmarks, tagging, custom commands, and extensive configuration through Python-based config files.

Installation

# Ubuntu/Debian
sudo apt install ranger

# Fedora
sudo dnf install ranger

# Arch Linux
sudo pacman -S ranger

# macOS via Homebrew
brew install ranger

# pip (any platform)
pip install ranger-fm

# Install optional preview dependencies
sudo apt install w3m-img highlight atool mediainfo poppler-utils

Preview Dependencies

ToolPurpose
w3m-img / ueberzugImage previews in terminal
highlight / batSyntax-highlighted text preview
atoolArchive content listing
pdftotext (poppler)PDF text preview
mediainfoAudio/video metadata
ffmpegthumbnailerVideo thumbnail previews

First-Time Setup

# Generate default config files
ranger --copy-config=all

# Creates:
# ~/.config/ranger/rc.conf      - Keybindings and settings
# ~/.config/ranger/rifle.conf   - File opener rules
# ~/.config/ranger/scope.sh     - File preview script
# ~/.config/ranger/commands.py  - Custom commands
KeyAction
hMove to parent directory
jMove down
kMove up
lOpen file/enter directory
ggGo to top of list
GGo to bottom of list
HGo back in history
LGo forward in history
~Go to home directory
ghGo to home directory
gdGo to /dev
geGo to /etc
gmGo to /media
gMGo to /mnt
gtGo to /tmp
guGo to /usr
gvGo to /var
gRGo to ranger config dir

File Operations

Selection

KeyAction
SpaceToggle selection on current file
vInvert selection
VEnter visual (select) mode
uvClear all selections

Cut, Copy, Paste

KeyAction
yyCopy (yank) selected files
ddCut selected files
ppPaste files
poPaste with overwrite
plCreate symlinks to copied files
pLCreate relative symlinks
udClear cut buffer
uyClear copy buffer

File Management

KeyAction
:touch filenameCreate new file
:mkdir dirnameCreate new directory
:rename newnameRename selected file
cwRename (opens rename prompt)
aRename - append before extension
ARename - append at end
IRename - insert at beginning
:deleteDelete selected files (confirms)
dDDelete selected files (confirms)

Bulk Rename

# Select files then run:
:bulkrename
# Opens filenames in $EDITOR, edit and save to apply

Search and Filter

KeyAction
/Search for file by name
nNext search result
NPrevious search result
fQuick filter/find
zfToggle filter (regex)
:filter patternFilter files by regex
:filter_inode_type dShow only directories
:filter_inode_type fShow only files

Tabs

KeyAction
Ctrl+NOpen new tab
Ctrl+WClose current tab
TabNext tab
Shift+TabPrevious tab
Alt+1-Alt+9Go to tab N

Bookmarks

KeyAction
m<key>Set bookmark to current directory
'<key>Go to bookmark
um<key>Delete bookmark

Sorting

KeyAction
orSort by natural order (default)
osSort by size
otSort by file type
oaSort by access time
ocSort by change time
omSort by modification time
onSort by name
oeSort by extension

Display Options

KeyAction
zhToggle hidden files
zpToggle previews
zPToggle directory previews
ziToggle image previews
SOpen shell in current directory
WView task manager

Configuration (rc.conf)

# ~/.config/ranger/rc.conf

# Show hidden files
set show_hidden true

# Preview settings
set preview_files true
set preview_directories true
set preview_images true
set preview_images_method ueberzug

# Column ratios (parent:current:preview)
set column_ratios 1,3,4

# Appearance
set draw_borders both
set unicode_ellipsis true
set confirm_on_delete multiple

# VCS integration (git, hg, svn)
set vcs_aware true
set vcs_backend_git enabled

# Mouse support
set mouse_enabled true

# Sorting
set sort natural
set sort_case_insensitive true
set sort_directories_first true

# Custom keybindings
map <C-f> fzf_select
map X shell -f extract %f
map Z shell tar -czf %f.tar.gz %s
map mkd console mkdir%space
map crf console touch%space

# Bookmarks
map gD cd ~/Downloads
map gP cd ~/Projects

File Opener Configuration (rifle.conf)

# Text files
mime ^text, label editor = ${VISUAL:-$EDITOR} -- "$@"

# Images
mime ^image, has feh = feh -- "$@"
mime ^image, has sxiv = sxiv -- "$@"

# Video/Audio
mime ^video, has mpv = mpv -- "$@"
mime ^audio, has mpv = mpv -- "$@"

# Documents
ext pdf, has zathura = zathura -- "$@"
ext docx?, has libreoffice = libreoffice -- "$@"

# Archives
ext tar|gz|bz2|xz|zip|rar|7z, has atool = atool -x -- "$@"

Custom Commands (commands.py)

from ranger.api.commands import Command
import os

class fzf_select(Command):
    def execute(self):
        import subprocess
        fzf = self.fm.execute_command(
            "find . -type f 2>/dev/null | fzf",
            stdout=subprocess.PIPE
        )
        stdout, _ = fzf.communicate()
        if fzf.returncode == 0:
            selected = os.path.abspath(stdout.decode('utf-8').strip())
            if os.path.isdir(selected):
                self.fm.cd(selected)
            else:
                self.fm.select_file(selected)

Shell Commands

PrefixBehavior
!commandRun command and wait for input
@commandRun command in background
#commandRun command and page output
s / SOpen shell in current directory

Macros

MacroMeaning
%fCurrent file
%dCurrent directory
%sSelected files
%tTagged files

Troubleshooting

IssueSolution
No image previewsInstall ueberzug or w3m-img; set preview_images_method
Slow startupReduce scope.sh complexity; disable VCS
No syntax highlightingInstall highlight or bat
Colors look wrongCheck terminal color support; set TERM=xterm-256color
Cannot delete filesCheck file permissions
Custom commands not loadingCheck commands.py syntax; restart ranger
Key mappings not workingCheck for conflicts in rc.conf
Previews not updatingPress zp to toggle; check scope.sh permissions