ranger usage

ranger is a console file manager with VI key bindings. It provides a minimalistic and nice curses interface with a view on the directory hierarchy. It ships with rifle, a file launcher that is good at automatically finding out which program to use for what file type.

This article is written to exhibit the usage of ranger on macOS and Ubuntu-based OSs.

Install

# on macOS
brew install ranger
# on Ubuntu
sudo apt install -y ranger

Config

# config dir: ~/.config/ranger
ranger --copy-config=all

The ~/.config/ranger directory contains configuration files for the Ranger file manager. Here is what each file is for:

  • commands.py: Defines custom commands that can be executed within Ranger.
  • rc.conf: Contains general configuration options for Ranger.
  • rifle.conf: Determines which applications to use for opening different file types.
  • scope.sh: Determines which files to show in Ranger's file viewer.
  • ranger.conf: Contains configuration options specific to the Ranger file viewer.
  • history: Contains a history of commands executed within Ranger.
  • bookmarks: Contains a list of user-defined bookmarks for quickly navigating to frequently used directories.

Note: if use ~/.config/ranger, RANGER_LOAD_DEFAULT_RC needs to be set as false.

# bash
echo "export RANGER_LOAD_DEFAULT_RC=false" >> ~/.bashrc
# zsh
echo "export RANGER_LOAD_DEFAULT_RC=false" >> ~/.zshrc

Customized Config

Change file ~/.config/ranger/rc.conf:

set draw_borders both
set line_numbers true
set one_indexed false
# enable image previewing.
set preview_images true
set preview_images_method iterm2
set preview_max_size 1048576 # 1MB

On macOS, enabling image previewing is supposed to install imgcat:

# install
sudo wget -O /usr/local/bin/imgcat https://iterm2.com/utilities/imgcat
# add permission to the file
sudo chmod 777 /usr/local/bin/imgcat

Shortcuts

在浏览时常用的快捷键

S   切换到ranger最后浏览的目录
zh/退回键  显示隐藏文件
H   后退
L   前进
gg  跳到顶端
G   跳到底端
gh  go home
gn  新建标签(tab键切换标签)
f   查找(如果只有一个匹配结果会直接打开该目录或文件)
/   搜索
g   快速进入目录

vim操作一致的快捷键

yy      复制
dd      剪切
pp      粘贴
dD      删除(需要回车键确认)
cw      重命名
A       在当前名称基础上重命名
I       类似A, 但是光标会跳到起始位置
Ctrl-f  向下翻页
Ctrl-b  向上翻页

文件排序

on/ob   根据文件名进行排序(natural/basename)
oc      根据改变时间进行排序 (Change Time 文件的权限组别和文件自身数据被修改的时间)
os      根据文件大小进行排序(Size)
ot      根据后缀名进行排序 (Type)

oa      根据访问时间进行排序 (Access Time 访问文件自身数据的时间)
om      根据修改进行排序 (Modify time 文件自身内容被修改的时间)

书签

m       新建书签
`       打开书签
um      删除书签

标签

gn / Ctrl-n        新建标签
TAB / Shift-TAB    切换标签
gc / Ctrl-w        关闭标签