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 keybindingsrifle.conf
- File associations and opening rulesscope.sh
- File preview configurations
Navigation Essentials
Basic Movement
Key | Action |
---|---|
h | Go to parent directory |
j | Move down one item |
k | Move up one item |
l | Enter directory or open file |
gg | Go to top of list |
G | Go to bottom of list |
H | Go back in history |
L | Go forward in history |
Directory Navigation
Key | Action |
---|---|
gh | Go to home directory |
gr | Go to root directory |
gm | Go to /media |
gM | Go to /mnt |
gt | Go to /tmp |
gu | Go to /usr |
gv | Go to /var |
ge | Go to /etc |
Quick Navigation
Key | Action |
---|---|
' | Open bookmarks |
m | Set bookmark |
um | Delete bookmark |
cd | Change directory (prompt) |
~ | Go to home directory |
/ | Search for files |
n | Next search result |
N | Previous search result |
File Operations
Basic File Actions
Key | Action |
---|---|
Space | Select/deselect file |
v | Select all files |
V | Visual selection mode |
uv | Deselect all files |
yy | Copy (yank) selected files |
dd | Cut selected files |
pp | Paste files |
po | Paste and overwrite |
pl | Create symbolic links |
pL | Create relative symbolic links |
File Management
Key | Action |
---|---|
cw | Rename file |
a | Rename file (append mode) |
A | Rename file (insert at end) |
I | Rename file (insert at beginning) |
dD | Delete files permanently |
dT | Move to trash |
mkdir | Create directory |
touch | Create empty file |
File Information
Key | Action |
---|---|
i | Show file information |
du | Show disk usage |
? | Show help/keybindings |
f | Find files |
F | Find files (include hidden) |
Advanced Navigation Features
Tabs and Panes
Key | Action |
---|---|
gn | Create new tab |
gt | Go to next tab |
gT | Go to previous tab |
gc | Close current tab |
alt+1-9 | Switch to tab number |
S | Open shell in current directory |
! | Execute shell command |
Sorting and Filtering
Key | Action |
---|---|
on | Sort by name |
os | Sort by size |
ot | Sort by modification time |
oc | Sort by creation time |
oe | Sort by extension |
or | Reverse sort order |
zh | Toggle hidden files |
zf | Filter 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
Key | Action |
---|---|
ya | Copy filename |
yp | Copy full path |
yn | Copy filename without extension |
yd | Copy directory path |
Space | Select multiple files |
v | Select all files in directory |
Ctrl+v | Toggle visual selection |
Search and Filter
Key | Action |
---|---|
/ | Search forward |
? | Search backward |
n | Next search result |
N | Previous search result |
zf | Filter files by name |
zF | Filter files by extension |
zd | Filter directories only |
za | Toggle 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
Popular Plugins
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
- Ranger Official Documentation
- Ranger GitHub Repository
- Arch Linux Ranger Wiki
- Ranger Configuration Examples
- Ranger Colorschemes
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.