Ranger is a powerful, Vim-inspired file manager for the terminal that can dramatically speed up your command-line workflow. If you find yourself constantly switching between cd
and ls
to navigate your filesystem, ranger is the tool you’ve been missing. This guide will walk you through everything from installation to advanced customization, helping you become a ranger power user.
Installation
Getting started with ranger is simple. You can install it using pip
or your system’s package manager.
# Using pip
pip install ranger-fm
# On macOS with Homebrew
brew install ranger
# On Debian/Ubuntu
sudo apt-get install ranger
# On Arch Linux
sudo pacman -S ranger
Seamless Shell Integration
To make ranger even more powerful, you can integrate it with your shell so that when you exit ranger, you land in the directory you were last browsing. This is a game-changer for workflow efficiency.
Here’s a handy alias for your .bashrc
or .zshrc
that accomplishes this:
# Add this to your ~/.bashrc or ~/.zshrc
alias rr='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
With this alias, simply typing rr
will launch ranger. When you quit, your shell will automatically cd
into the last directory you were viewing in ranger.
The Three-Pane Interface
Ranger’s interface is divided into three columns:
- Left Pane: Shows the parent directory.
- Middle Pane: Shows the contents of the current directory.
- Right Pane: Shows a preview of the selected file or the contents of the selected directory.
This layout gives you a comprehensive view of your filesystem at a glance, allowing for quick navigation and file identification.
Essential Commands
Ranger uses Vim-like keybindings, which makes it incredibly fast to use once you get the hang of them.
Navigation
h
j
k
l
: Move left, down, up, and right, just like in Vim.gg
: Jump to the top of the file list.G
: Jump to the bottom of the file list.gh
: Go “home” to your user directory (~
).ge
: Go to/etc
.g/
: Go to the root directory (/
).
Pressing g
followed by another key is the primary way to jump to common directories. We’ll see how to customize these “go” commands later.
File Operations
yy
: Yank (copy) a file.pp
: Paste the copied file.dd
: Cut a file.F8
or:delete
: Delete the selected file(s).cw
: Rename the current file.A
: Append text to the filename (like Vim’sA
), often used to add a suffix such asbak
when creating backup files.I
: Prepend text to the filename (like Vim’sI
).
To perform an operation on multiple files, first select them using the spacebar, which highlights them. Then, use any of the file operation commands like yy
, dd
, or :delete
.
If you only need to copy the file path for use elsewhere (e.g., in the command line or an editor):
• yp
→ Copies the full path of the current file to the system clipboard. (This requires clipboard support to be configured, e.g., by installing xclip
or wl-clipboard
).
• yd
→ Copies the path of the current directory.
You can then paste the path directly outside the terminal (e.g., using Ctrl+V
or Cmd+V
).
Searching and Filtering
/
: Search for files in the current directory.f
: Filter files. Start typing, and ranger will only display files that match your input. This is extremely useful for quickly locating what you need in a crowded directory.
Pressing z
brings up a menu for toggling various settings. For example:
zz
: Show the filter bar in real time, which is even more useful than just usingf
.zh
: Toggle the display of hidden files (dotfiles). You can also useBackspace
to do this.zi
: Toggle image previews (if your terminal supports them).
Tabs
Ranger supports tabs, much like a modern file browser.
gn
or<C-n>
: Create a new tab.gc
or<C-w>
: Close the current tab.gt
orTab
: Switch to the next tab.
This is similar to opening multiple windows in a graphical file manager.
Bookmarks
You can set bookmarks to quickly jump to your favorite directories.
m<key>
: Mark the current directory with a key (for example,mw
to bookmark your work directory).'<key>
: Jump to the bookmarked directory (for example,'w
to go to your work directory).
Running Shell Commands
One of ranger’s most powerful features is its seamless integration with the shell. You can run commands without ever leaving the file manager, which is perfect for tasks like checking git status, creating archives, or running scripts.
- :shell
: Execute any shell command. For example, :shell git status
will run the command in the current directory and display the output. Ranger provides a convenient shortcut for this: just press!
. - Macros for Files: Ranger uses macros to refer to the files you have selected. This is where it gets really powerful.
%f
: The currently highlighted file.%d
: The current directory.%s
: The names of all selected files (e.g.,file1.txt file2.log
).%c
: The full paths of all selected files.
Example: Compressing Files
Imagine you want to compress several log files into a single tar.gz
archive.
- Navigate to the directory containing your logs.
- Select the files you want to archive using the
spacebar
. - Press
!
to open the shell prompt, and type:tar -czvf logs.tar.gz %s
- Hit Enter. Ranger will execute the command, using the
%s
macro to pass the names of your selected files totar
.
This workflow is incredibly efficient because you don’t need to manually type out long file names or switch back and forth between your shell and file manager.
Configuration and Customization
Ranger’s true power lies in its customizability. To get started, copy the default configuration files to your home directory:
ranger --copy-config=all
This will create a ~/.config/ranger
directory with several configuration files. The main file you’ll want to edit is rc.conf
.
Custom Keybindings
You can add your own keybindings in rc.conf
. For instance, to create a shortcut g1
that jumps directly to your PostgreSQL configuration directory, add this line:
map g1 cd /etc/postgresql/14/main/
Now, typing g1
in ranger will take you straight there. This is perfect for accessing frequently used project or configuration directories.
Here is a snippet of the default keybindings for the g
command to give you an idea of what’s possible:
# Default 'g' keybindings
key command
L cd -r %f
l cd -r .
/ cd /
d cd /dev
e cd /etc
m cd /media
h cd ~
...
By customizing these keybindings, you can tailor ranger to perfectly fit your workflow.
Conclusion
Ranger is more than just a file manager; it’s a productivity tool that can fundamentally change how you interact with your filesystem in the terminal. By embracing its Vim-like keybindings and taking the time to customize it, you’ll be able to navigate and manage your files with unparalleled speed and efficiency. Give it a try—you might just wonder how you ever lived without it.