Hund

Ranger - My favourite file manager

August 20, 2020

Ranger is a file manager written in Python that uses the well-known text-based interface ncurses. The layout for displaying files and folder is called Miller columns, a three column based layout that’s commonly used for file managers. Ranger is a Vi-like file manager, which means that the keybindings and workflow is highly inspired from the Vi text editor. It even features some (optional) support for the mouse, but what makes it great (if you ask me) is the epic support for a key-based workflow.

My setup with Ranger and the Solarized colourscheme.
My setup with Ranger and the Solarized colourscheme.

My adventures with Ranger

Even though I’ve been an avid user of everything text-based for a long time, I was sceptic over using a text-based file manager. Could it really be as fast or as convenient as a graphical file manager? Well. It turned out I was wrong, so wrong!

The first days with Ranger felt a little bit awkward, kind off like how it felt with Vim the first time, but at the same time you instantly knew you were onto something good. I was using the basic navigation with the keys j and k to navigate up and down, gg and G to jump to the top and bottom and '<LETTER> for my bookmarks. While it did work, it wasn’t efficient and browsing larger folders took me forever. This could have all been avoided if I hadn’t just quickly skimmed through the documentation and instead thoroughly read (at least most of) the documentation first.

It wasn’t until I read the whole documentation that I found out about the “find” feature, a feature that lets you quickly search for files and folders. It works by hitting the letter f and then typing some of the characters from the file or folder you’re looking for. If you end up with a unique hit it will open the file or folder directly and you can also at any time navigate between the hits with the keys n and tab. This way of navigating made a large impact on the efficiency for me and it also convinced me that a text-based file manager can actually be more efficient.

With that said. I wasn’t 100% satisfied with the find-feature until I found out about a neat little tweak to the it! By rebinding f to the function scout -ftsea%space I was now able to visually filter out all non-hits, making it a lot easier to find what I’m looking for. I made a little animated GIF-image to demonstrate what I’m talking about:

If you want to do the same thing, add this line to your configuration file ~/.config/ranger/rc.conf:

map f console scout -ftsea%space

Features

Ranger comes with a lot of features and if that’s not enough, it’s also possible to add new functionality with scripts and plugins. As this is meant to be an introduction to Ranger I will only cover some basics here.

Thumbnails

The first thing you might ask yourself is: “What about thumbnails?”. Well. Showing thumbnails for images might be considered to be one of the most basic features a file manager should have by some. And they’re right.

Ranger can show a (single) preview/thumbnail of pretty every file there is—even archives (using atool) and torrent-files (using transmission-show)—the issue is that it can only preview the currently marked file. Which is perfectly fine for everything but images. A solution to this is the image viewer sxiv, which can show thumbnails for images.

I wrote about sxiv back in 2018: “sxiv - A simple Vi-like image viewer”. It’s a great lightweight and scriptable image viewer that I highly recommend everyone checking out!

The keybindings

What makes Ranger truly great is the keybindings. To give you an idea how it could work, I have included some of the common keybindings for me. Some of them are defaults and some of them are my own. I’m not really sure which ones are the defaults or not though, I’ve been using Ranger for a long time now.

File management

Command Description
H Show hidden files and folders.
r Open with <APPLICATION>.
D Delete the marked file or the selected files.
<Space> Selects the current file/folder.
v Marks all files and folders in the current directory.
a Edit the name of the file/folder by putting the cursor last.
I Edit the name of the file/folder by putting the cursor first.
cw Change the name of the file/folder.
o Sort current directory. oa to sort by time os to sort by name size and so on.
'<LETTER> Jump to bookmark.
m<LETTER> Bookmarks the current directory.
:bulkrename Lets you bulk rename the selected files and folders by using your $EDITOR.

Tabs

Command Description
gn opens a new tab.
gc closes the current tab.
<Tab> switches tab to the right.
<Shift>+<Tab> switches tab to the left.

Some of my custom keybindings

This is some of the keybindings that I actually know that I have added myself.

Command Description
F Executes detox %f on the current file or folder. Detox makes file names pretty by removing troublesome characters and spaces.
Md Creates a folder.
U Uploads the selected file(s) and/or folder(s) to my Nextcloud account using shareLinkCreator.
Pp Creates a PDF-document of the selected document using Pandoc.
Ph Creates a HTML-document of the selected document using Pandoc.
px Extracts the archive using atool.
pat Creates an archive using tar.
paz Creates an archive using zip.
w Sets the current image as a wallpaper using feh.

If you’re at any time lost and/or need any kind of help in Ranger, you can just press the key ? to bring up this dialog that will help you:

View [m]an page, [k]ey bindings, [c]ommands or [s]ettings? (press q to abort)

Plugins

To install a plugin you simply copy it to the folder $XDG_CONFIG_HOME/ranger/plugins/. I only have one plugin myself and that’s a plugin called plugin_file_filter.py, it’s a plugin that visually hide files and folders. Why? The main reason I installed it is so I can hide the folder ~/Desktop. I don’t have a desktop, so why would I want to see the folder?

You can find more plugins on their wiki.

There’s more

This is far from everything that Ranger can do, my hope is that what I covered here today is enough to help peak the interest for you with Ranger and to try it out yourself!

I highly recommend you checking out their cheatsheet (PNG / SVG), the official user guide and the rest of the wiki for all the information available about Ranger.

And if you’re interested in looking at my latest public configuration for Ranger it’s available online via my public Git-repository for Ranger and other dotfiles.

Meta

No Comments

Use the e-mail form, if you wish to leave feedback for this post. Markdown is supported. [Terms of service]