Ranger - A Very Efficient CLI File Manager

works from within a terminal

You'll especially appreciate the ranger file manager if you are a touch typist, and/or a user of the vi or vim text editor, as along arrow keys, it utilizes the h, j, k, and l keys for rudamental navigation, among others!

Show more navigational key bindings that overlap with vi(m) text editor's
Ctrl-F, Ctrl-B - move a page down, up
Ctrl-U, Ctrl-D - move a half page down, up
gg, G - move to the top, bottom
/ - search
n, N - finding the next, previous files

Bookmarking

m<key> - bookmark the current directory with the name <key> (for instance: ma)
'<key> - jump to the bookmark with the name <key> (for instance: 'a)
• The <key> can be any lowercase and uppercase letter or digit.
'' (pressing the single quote key twice) - the special bookmark, being automatically set to the previous directory visited; thus you can conveniently jump between two directories by just pressing the '' combo

Some Key-Bindings I've Found Particularly Useful

i - show a textual information of the current file (can show a file's metadata giving that appropriate program is installed on the system, for example exiftool). Pressing q will exit the preview mode and return to the list of files and directories
E - edit the current file
s - bring the shell interpreter to execute a one-off command in the directory currently displayed in the main frame
r - shows a selector of which program to use to open the current file
yy - copy (yank), pp - paste, dd - cut a current file or a selection of files
Space - append a file to a selection list
v - invert selection (deselects the selected file(s) and selects the rest)
uv - deselect file(s)
? - open the help menu. To see all available key bindings, press k in the opened menu

One feature I'm pretty sure you would like to have is that when you exit ranger, it would change the current directory of the shell to the one that was lastly viewed in the file manager.

Luckily for you there's a shell function that makes it possible. I think I've found it at the http://manpages.ubuntu.com/manpages/precise/man1/ranger.1.html long time ago, here it is:

For bash

ranger-cd() { tempfile='/tmp/chosendir' /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then command cd -- "$(cat "$tempfile")" fi rm -f -- "$tempfile" } # This binds Ctrl-O to ranger-cd: bind '"\C-o":"ranger-cd\C-m"'

For zsh

ranger-cd() { tempfile='/tmp/chosendir' /usr/bin/ranger --choosedir="$tempfile" "${@:-$(pwd)}" test -f "$tempfile" && if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then cd -- "$(cat "$tempfile")" fi } # This binds Ctrl-O to ranger-cd: bindkey -s '^O' 'ranger-cd^M'

Because the given pieces of code also bind the Ctrl-O to execute the newly created ranger-cd shell function, after sourcing the file you've put the function in, you can open ranger with no time, great!

A Very Efficient CLI (Terminal) File Manager for UNIX-Like OS
This page was last updated on March 14, 2021
No comments have been posted so far
Leave a Comment