Ranger File Manager Complete Reference Guide

Ranger is a powerful terminal-based file manager that brings vim-like navigation and keybindings to file system operations. This comprehensive guide covers everything from basic navigation to advanced configuration, making it an essential tool for command-line productivity.

Whether you’re new to ranger or looking to optimize your workflow, this reference provides practical commands, configuration examples, and tips for maximizing efficiency in terminal file management.

Getting Started with Ranger

Installation

Arch Linux:

sudo pacman -S ranger

Ubuntu/Debian:

sudo apt install ranger

macOS (Homebrew):

brew install ranger

First Run and Initial Setup

Launch ranger for the first time:

ranger

Generate default configuration files:

ranger --copy-config=all

This creates configuration files in ~/.config/ranger/:

  • rc.conf - Main configuration and keybindings
  • rifle.conf - File associations and opening rules
  • scope.sh - File preview configurations

Basic Movement

KeyAction
hGo to parent directory
jMove down one item
kMove up one item
lEnter directory or open file
ggGo to top of list
GGo to bottom of list
HGo back in history
LGo forward in history

Directory Navigation

KeyAction
ghGo to home directory
grGo to root directory
gmGo to /media
gMGo to /mnt
gtGo to /tmp
guGo to /usr
gvGo to /var
geGo to /etc

Quick Navigation

KeyAction
'Open bookmarks
mSet bookmark
umDelete bookmark
cdChange directory (prompt)
~Go to home directory
/Search for files
nNext search result
NPrevious search result

File Operations

Basic File Actions

KeyAction
SpaceSelect/deselect file
vSelect all files
VVisual selection mode
uvDeselect all files
yyCopy (yank) selected files
ddCut selected files
ppPaste files
poPaste and overwrite
plCreate symbolic links
pLCreate relative symbolic links

File Management

KeyAction
cwRename file
aRename file (append mode)
ARename file (insert at end)
IRename file (insert at beginning)
dDDelete files permanently
dTMove to trash
mkdirCreate directory
touchCreate empty file

File Information

KeyAction
iShow file information
duShow disk usage
?Show help/keybindings
fFind files
FFind files (include hidden)

Advanced Navigation Features

Tabs and Panes

KeyAction
gnCreate new tab
gtGo to next tab
gTGo to previous tab
gcClose current tab
alt+1-9Switch to tab number
SOpen shell in current directory
!Execute shell command

Sorting and Filtering

KeyAction
onSort by name
osSort by size
otSort by modification time
ocSort by creation time
oeSort by extension
orReverse sort order
zhToggle hidden files
zfFilter files

Configuration and Customization

Essential Configuration Options

Edit ~/.config/ranger/rc.conf:

# Show hidden files by default
set show_hidden true
 
# Enable image previews
set preview_images true
set preview_images_method w3m
 
# Use better column ratios
set column_ratios 1,3,4
 
# Set default editor
set editor nvim
 
# Enable mouse support
set mouse_enabled true
 
# Set colorscheme
set colorscheme default
 
# Show file size in human readable format
set display_size_in_main_column true
set display_size_in_status_bar true
 
# VCS integration
set vcs_aware true
set vcs_backend_git enabled
set vcs_backend_hg enabled
set vcs_backend_bzr enabled
set vcs_backend_svn enabled

Custom Keybindings

Add custom keybindings to rc.conf:

# Custom navigation
map gd cd ~/Documents
map gD cd ~/Downloads
map gc cd ~/.config
map gp cd ~/Projects
 
# Quick file operations
map DD shell trash-put %s
map ex extract %f
map co compress %f
 
# Git operations
map gs shell git status
map ga shell git add %f
map gc shell git commit
 
# System operations
map bg shell setbg %f
map r shell $EDITOR %f
map R reload_cwd

File Type Associations

Edit ~/.config/ranger/rifle.conf:

# Text files
ext txt|md|py|js|html|css|json = $EDITOR "$1"
 
# Images
mime ^image = feh "$1"
 
# Videos
mime ^video = mpv "$1"
 
# Audio
mime ^audio = mpv "$1"
 
# PDFs
ext pdf = zathura "$1"
 
# Archives
ext zip|rar|7z|tar|gz = aunpack "$1"
 
# Web files
ext html|htm = firefox "$1"

Advanced Features

Directory Persistence

To make ranger remember your location between sessions, add this alias to your shell configuration:

# Add to ~/.bashrc or ~/.zshrc
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'

Or use this more robust function:

# Enhanced ranger function
ranger_cd() {
    local IFS=$'\t\n'
    local tempfile="$(mktemp -t tmp.XXXXXX)"
    local ranger_cmd=(
        command
        ranger
        --cmd="map Q chain shell echo %d > "$tempfile"; quitall"
    )
    
    ${ranger_cmd[@]} "$@"
    if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; then
        cd -- "$(cat "$tempfile")" || return
    fi
    command rm -f -- "$tempfile" 2>/dev/null
}
alias ranger='ranger_cd'

Bulk Operations

KeyAction
yaCopy filename
ypCopy full path
ynCopy filename without extension
ydCopy directory path
SpaceSelect multiple files
vSelect all files in directory
Ctrl+vToggle visual selection

Search and Filter

KeyAction
/Search forward
?Search backward
nNext search result
NPrevious search result
zfFilter files by name
zFFilter files by extension
zdFilter directories only
zaToggle filters

External Program Integration

Configure external programs in rc.conf:

# Set default applications
set open_all_images true
set preview_images true
set use_preview_script true
set preview_script ~/.config/ranger/scope.sh
set preview_images_method w3m
 
# Terminal integration
set update_title true
set update_tmux_title true
set shorten_title 3

Performance Optimization

Speed Improvements

# Disable slow operations
set automatically_count_files false
set show_selection_in_titlebar false
set display_tags_in_all_columns false
 
# Optimize previews
set preview_files true
set preview_directories true
set collapse_preview true
set preview_max_size 10485760  # 10MB
 
# Cache settings
set preview_images_method w3m
set w3m_delay 0.02
set w3m_offset 0

Memory Management

# Limit cached files
set max_filesize_for_preview_image 10485760
set max_console_history_size 50
set max_history_size 20

Troubleshooting

Common Issues

Preview not working:

# Install required dependencies
sudo pacman -S w3m highlight atool lynx elinks poppler mediainfo
 
# Check scope.sh permissions
chmod +x ~/.config/ranger/scope.sh

Slow performance:

# Disable expensive operations
set vcs_aware false
set preview_images false
set use_preview_script false

Colors not displaying:

# Check terminal color support
echo $TERM
export TERM=xterm-256color
 
# Try different colorscheme
set colorscheme snow

Mouse not working:

# Enable mouse support
set mouse_enabled true
 
# Check terminal mouse support
set mouse_enabled false  # if issues persist

Plugins and Extensions

ranger-archives: Enhanced archive support

git clone https://github.com/maximtrp/ranger-archives.git
cp ranger-archives/plugins/* ~/.config/ranger/plugins/

ranger-devicons: File type icons

git clone https://github.com/alexanderjeurissen/ranger_devicons.git
cp ranger_devicons/devicons.py ~/.config/ranger/plugins/

ranger-zoxide: Smart directory jumping

# Install zoxide first
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
 
# Add to rc.conf
map cz console z%space

Custom Commands

Add to ~/.config/ranger/commands.py:

from ranger.api.commands import Command
 
class extract(Command):
    def execute(self):
        import os
        from ranger.core.runner import Runner
        
        def refresh(_):
            cwd = self.fm.thisdir
            cwd.load_content()
            
        one_file = self.fm.thisfile
        cwd = self.fm.thisdir
        original_path = cwd.path
        
        if one_file.extension in ['zip', 'rar', '7z', 'tar', 'gz']:
            self.fm.run('aunpack ' + one_file.path)
            self.fm.reload_cwd()
 
class compress(Command):
    def execute(self):
        selected_files = self.fm.thistab.get_selection()
        if not selected_files:
            return
        
        archive_name = self.arg(1)
        if not archive_name:
            self.fm.notify("Usage: compress <archive_name>")
            return
            
        files = " ".join([f.path for f in selected_files])
        self.fm.run(f'apack {archive_name} {files}')
        self.fm.reload_cwd()

Desktop Environment Integration

Complete Desktop Setup

For users setting up a complete development environment, ranger integrates seamlessly with modern desktop environments. The automated Hyprland desktop setup includes ranger as part of a comprehensive terminal-based workflow alongside tmux, neovim, and other productivity tools.

Development Workflow Integration

Ranger works particularly well within the development environment described in the complete environment documentation. The integration provides seamless file management across terminal applications, making it ideal for developers who prefer keyboard-driven workflows.

Tmux Integration

For seamless integration with tmux terminal multiplexer, see the complete tmux configuration guide which includes custom keybindings and modal navigation similar to ranger’s vim-style interface.

# Add to .tmux.conf
bind-key r run-shell 'ranger'

Neovim Integration

Integrate ranger with Neovim for powerful file management within your development workflow. The complete Neovim setup guide covers advanced editor configuration that complements ranger’s file management capabilities.

" Add to init.lua for Neovim
vim.keymap.set('n', '<leader>r', ':!ranger<CR>', { desc = 'Open ranger' })

Shell Integration

Zsh integration:

# Add to .zshrc
bindkey -s '^o' 'ranger\n'  # Ctrl+O opens ranger

Bash integration:

# Add to .bashrc
bind '"\C-o":"ranger\n"'  # Ctrl+O opens ranger

References and Resources

Questions Answered in This Document

Q: How do I navigate directories efficiently in ranger? A: Use vim-style navigation with h (parent), j/k (up/down), l (enter), and shortcuts like gh (home), gr (root), and bookmarks with m to set and ' to access.

Q: How can I make ranger remember my location when I exit? A: Add the alias alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=cat LASTDIR”’` to your shell configuration file.

Q: What are the essential ranger keybindings for file operations? A: Key bindings include Space (select), yy (copy), dd (cut), pp (paste), cw (rename), dD (delete), and mkdir (create directory).

Q: How do I configure ranger to show hidden files and enable previews? A: Edit ~/.config/ranger/rc.conf and add set show_hidden true and set preview_images true with set preview_images_method w3m.

Q: How can I customize ranger’s file associations? A: Edit ~/.config/ranger/rifle.conf to define which applications open specific file types, using patterns like ext txt = $EDITOR "$1" for text files.

Q: What are the best performance optimizations for ranger? A: Disable expensive operations with set automatically_count_files false, limit preview sizes, and consider disabling VCS awareness if not needed.

Q: How do I search for files and navigate search results in ranger? A: Use / to search forward, ? to search backward, n for next result, N for previous result, and zf to filter files by name.

Q: Can I use ranger with tabs and how do I manage them? A: Yes, use gn (new tab), gt/gT (switch tabs), gc (close tab), and Alt+1-9 to jump to specific tab numbers.

Q: How do I integrate ranger with other command-line tools? A: Use shell commands with !, create custom keybindings in rc.conf, and integrate with tools like git, tmux, and text editors through custom commands.

Q: What should I do if ranger previews aren’t working? A: Install dependencies like w3m, highlight, atool, and mediainfo, ensure scope.sh is executable, and check that preview_images_method is set correctly.