Setting up single navigation pane in Ranger and why it’s a good idea

Navigating complex directory structures efficiently is crucial for any developer or system administrator, and Ranger, a powerful terminal-based file manager, excels at this task. In this article, I will guide you through setting up a single navigation pane in Ranger, ensuring a streamlined and focused file management experience. Whether you're new to Ranger or looking to optimize your workflow, this tutorial will provide you with the necessary steps and tips to enhance your productivity. Let's dive into configuring Ranger to suit your needs and make navigating your file system a breeze.

By default, Ranger starts in a 3-pane view, which makes it unique but not very practical. Fortunately, this can be easily changed.

If you want to skip past gibberish and straight to solution, click here.

For many years, I used Total Commander (the best file manager on Windows, or at least it used to be). Maximized, I had the classic two-pane design. One day, after buying my first full HD monitor (prehistoric times indeed), I opened the program and realized how much space I was losing by having that second pane. Half of my screen space, to be precise.

The truth is, in that classic Norton Commander design, half the screen is a glorified directory link. Yes, it can be used to compare folders or get a broader multi-directory view, which can help make sense of things.

But those are situational. Most of the time, one pane is important; the other just points to where to copy or move files from. It is a waste of space.

If reference is indeed its main purpose, the second pane might as well have a vertical split option and just hold stackable directory paths, with a pre-selected modifier and a randomly chosen key generated for each one to allow operations to/from these.

This would be a very good use of space and a real lifesaver when working on projects with complex directory structures. But one link taking up half of the screen estate?

This isn’t a problem if someone is used to having maximized applications and alt+tabbing between them. Plenty of that space will be wasted in most programs, but that won’t matter anyway since we decide to focus on one thing at a time. For many people, having multiple things at once makes them lose focus. That’s why distraction-free modes in editors are popular.

I often do multiple things at once and so I’d rather have them next to each other to be able to compare and rewrite code snippets, etc. Often, I have to run different scripts at once and need to see how they perform. And so every bit of space is important.

That’s why, after switching to Linux a few years back, I decided to look for a file manager that would just have one pane… and ended up using the one that has three!

In Ranger’s default view, the parent directory, which is always one keypress away, takes one-third of the space. Another shows the sub-directory. How often is that actually useful?

Some of the most advanced ‘navigators’ I’ve met just use the command line for their daily routines. They get zero information even about the current directory when navigating, and yet not only can they function, but they are absurdly fast with their operations.

Even when we actually need to scan a subfolder for the presence of a file or two, doing a recursive search will be much faster and much less eye-straining. A view of multiple directories at once is a gimmick, something that is there probably because it made the first program of its kind stand out from the crowd.

Since I absolutely loved Ranger from the get-go, I wasn’t going to let this spoil things. Even if there were no option to change it, I would probably stick to it still. Fortunately, this is not the case.

Editing config file

Ranger stores configuration in two files: rc.conf (program settings, key bindings) and rifle.conf (file associations). We will be editing the first one.

You can find it in ~/.config/ranger directory. If it’s not there, paste this command in console and run it:

Ranger –copy-config=all

Now both files should be there.

The first setting command that interests us is:

set viewmode [mode]

This command takes one of two mode arguments:

The multipane view puts an equation mark between tabs and panes. If there are no tabs, there is one pane. Every new tab creates a new pane, splitting the available space evenly between all displayed ones.

Another command complements it:

set column_ratios 1

It takes 0 to 3 arguments. Giving it 4 or more is not considered properly in code. Setting it up in the config file and then starting Ranger runs it in a broken state.

For example, feeding it ‘1,2,1’ will set the parent and child directory panes to take 50% of the total window width, while the main window in which we navigate will occupy the other 50%. Keep in mind, though, that as of now, it only works for miller mode.

It would be convenient to set it to something like this:

set column_ratios 5,1

If multipane was set, this command could only accept two arguments: the first one pointing to the relative size of the currently focused tab, the other to all other unfocused ones.

In miller mode, if we only give it one value, it will just give us one column. And since the one in which we traverse directories is the only one we can’t live without, it is set to be the only one remaining in such a case.

Notice that both setting column_ratios to 0 and not writing any number at the end will also give the same result.

So, if someone does not ever intend to use tabs, they might just set viewmode to multipane and be done with it, but there’s no need to do that. Today we don’t use it, maybe tomorrow we will. Let’s set it to miller and set column_ratios to 1.

That’s not all, though. The problem arises when we hover over a file in Ranger. It’s going to get previewed. Now, half the screen will be occupied by a file each time we encounter a previewable one. Sometimes, that’s useful, but mostly it’s distracting.

The solution is to disable file previews:

set preview_files false

Summary

  1. Check if the file rc.conf exists in the path: ~/.config/ranger/. If not, paste and execute the following command: ranger –copy-config=all. Now the file should be there.
  2. Open it in a text editor
  3. Add the following lines inside it:
    • set viewmode miller
    • set column_ratios 1
    • set preview_files false

But why cripple myself with one pane when I can have more?

If removing two panes will leave the user with empty space that they do not intend to populate in any way, it might be better to leave the default 3 panes on (unless the extra ones are distracting).

Even for people who don’t get much use from them but are used to having them always on, it can feel like the navigation is now crippled.

Don’t fret, though. First of all, we have tabs. Switching between them requires a single keystroke.

For copying files/directories, a popular approach is to:

Or reverse it if the file source directory and not the destination directory is where we want to do the next thing.

It takes the same amount of keystrokes to complete as doing that operation while jumping between panes. We just jump between tabs instead of panes. We lose visibility of a reference folder the entire time but require half the program space to complete it.

For diff purposes, tabbing is great too. We can, for example, check some potentially modified project folder against a backup of the same content and switch between them to quickly see if there are some differences in files. As they take turns occupying the same space, it will be easier to notice differences.

There are better solutions for scenarios like that, but for a quick check, it is often convenient to do it this way.

Second, we can simplify things further. We always move legally downloaded movies to the ‘movie’ folder, legally downloaded mp3 tracks to the ‘mp3’ folder, etc. Some folders receive a high amount of traffic. Almost everyone has a routine.

Many people who despise file managers and people who use them have bash aliases to folder paths set to allow easy moving. In Ranger, it is also very simple to do.

Ranger adopted one of Vim’s greatest tools - leader keys. No need to press a modifier key (of which there are few) and control its press and release in combination with another key to trigger some operation bound to that particular shortcut. Almost any key can lead, and it doesn’t have to be kept pressed.

And so, we can do this:

map mp shell mv %s /mnt/ssd/books/programming
map mn shell mv %s /mnt/files/img/nakedpersons
map ma shell mv %s /mnt/files/music/ambient

We select all the books we want to move, then press ‘mp’ and we’re done. No need to go to any folder or open any tabs. A simple two-step operation.

If having two directories next to each other is a necessity at some point, nothing stops us from using a terminal multiplexer. So long as we remember that two separate Ranger instances can’t pass things between them, as Ranger doesn’t start a system daemon that could move that information. Another fantastic file manager, nnn, has that functionality.

The same can be done with copying or any other shell command that takes a list of files and does something to them. Such is the amazing flexibility of the command line, and as a result, of programs that allow sending some input to it for further processing, like Ranger.

Another fantastic tool that supercharges single-pane navigation is history. In rc.conf, we can set:

map h history_go -1
map H history_go 1

By default, the ‘h’ key is used for navigation in Ranger, as it is in Vim. I am using the Colemak keyboard layout, so for me this key is free, which allows for a nice mnemonic binding. You can set it to any key you have available.

In a default config Ranger use, going back in history will mostly go to the directory from which we came, which will be one level higher or lower in the directory structure. Moving forward will do the opposite and will, of course, only work if we already went back in history (like redo in text editors).

But when we have all sorts of map [key(s)] cd /some/path shortcuts and jump between them, those two bindings become way more powerful. And we can bookmark folders on the fly as well (‘m’ saves the current folder to bookmarks, tilde and ‘`’ keys open a list of bookmarked folders).

Final word

Setting up a single navigation pane in Ranger is a small tweak that can significantly enhance your file management workflow. By reducing visual clutter and focusing on one pane, you can navigate directories with greater ease and efficiency. This setup not only simplifies your interaction with Ranger but also helps you stay focused on your tasks without unnecessary distractions. As you continue to customize and optimize Ranger to fit your unique needs, you’ll find that these small adjustments can lead to substantial improvements in your overall productivity.

Thank you for following along with this guide. If you found it helpful, I encourage you to explore more customization options within Ranger and share your experiences. Feel free to reach out if you have any questions or if you need assistance with your projects. Happy navigating!