安装

1
sudo pacman -S ranger

使用

1
ranger

如果打开ranger后退出显示下面的错误:

1
Warning: Unable to set locale.  Expect encoding problems.

可以在~/.bashrc中添加:

1
2
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"

如果你用的是zsh,需要在~/.zshrc中添加(具体就看你用的是什么shell)

配置

官方文档:Ranger User Guide

生成配置文件:

1
ranger --copy-config=all

会生成配置文件~/.config/ranger/rc.conf~/.config/ranger/rifle.conf

输出:

1
2
3
4
5
creating: /home/ttiee/.config/ranger/rifle.conf # 指定文件类型默认打开方式
creating: /home/ttiee/.config/ranger/commands.py # 命令配置文件
creating: /home/ttiee/.config/ranger/commands_full.py # 命令配置文件
creating: /home/ttiee/.config/ranger/rc.conf # 选项设置和快捷键
creating: /home/ttiee/.config/ranger/scope.sh # 设置预览文件的方式

Please note that configuration files may change as ranger evolves.
It’s completely up to you to keep them up to date.

To stop ranger from loading both the default and your custom rc.conf,
please set the environment variable RANGER_LOAD_DEFAULT_RC to FALSE.

如果想停止加载默认的rc.conf,可以设置环境变量RANGER_LOAD_DEFAULT_RCFALSE

1
export RANGER_LOAD_DEFAULT_RC=FALSE

cd到~/.config/ranger目录,编辑rc.conf文件。

1
cd ~/.config/ranger
1
vim rc.conf

图片预览

官方文档:Image Previews

编辑rc.conf文件,设置预览图片。

1
set preview_images true

默认是使用w3m预览图片的,先安装w3m

1
sudo pacman -S w3m

但我的w3m预览不了图片,所以我使用ueberzug预览图片。

1
sudo pacman -S ueberzugpp # ueberzug已经被废弃了,使用ueberzugpp

编辑rc.conf文件,设置预览图片的方式。

1
set preview_images_method ueberzug

图片预览

语法高亮

安装highlight

1
sudo pacman -S highlight

语法高亮

pdf预览

安装pdftotext

1
sudo pacman -S poppler

编辑rifile.conf文件,设置预览pdf的方式。

doc预览

安装docx2txt

1
sudo pacman -S docx2txt

编辑rifile.conf文件,设置预览doc的方式。

常用快捷键

快捷键就和vim一样的,而且还会有提示。

一些常用的快捷键:

快捷键说明
zh(或CTRL+h)显示隐藏文件
g开头的快捷键跳转到指定的目录(下方有提示)
space选中/取消选中
v反选
:bulkrename批量重命名
dd剪切
yy复制
pp粘贴
S在当前目录下打开shell
shell vim在当前目录下打开vim
cw重命名
F7创建文件夹
i进入文件
I文件重命名(在开头)
a文件重命名(不含拓展名)
A文件重命名(含拓展名)
q退出
dU显示文件夹大小
o排序
Ctrl+n新建标签页
Alt+数字切换标签页
Ctrl+w关闭标签页
/搜索
n下一个搜索结果
N上一个搜索结果
/ + 搜索内容 + Tab直接跳转到搜索结果

官方文档说明

Key bindings and hints

A lot of commands can be performed using key bindings, making use of the hints to find the correct mapping.

Command hints show up whenever a mapping has multiple continuations:
g for navigation and tabs
r for :open_with command
y for yank(copy)
d for cut/delete
p for paste
o for sort
. for filter_stack
z for changing settings
u for “undo”
M for linemode
+, -, = for setting access rights to files

Command hints consist of keys in the left column and corresponding commands in right column. When you press a key the corresponding command is invoked or further hints are revealed.

Configuration

ranger uses 4 main configuration files:

  • rc.conf is used for setting various options and binding keys to functions.
  • rifle.conf decides which program to use for opening a file.
  • scope.sh is a shell script used to generate previews for various file types.
  • commands.py contains various functions’ implementation, written in Python, used to modify ranger’s behavior, and implement your own Custom Commands.

Use ranger --copy-config=rc or one of rifle, scope, commands to copy the default config files to ~/.config/ranger and modify them there, only copy the files you want to edit. This way ranger won’t keep using outdated configuration files when you update it, except for the ones you do copy, you’re responsible for keeping those up to date. Be aware that for rc.conf and commands.py, ranger reads both the global and the user’s config (in that order). It allows the user to maintain only a small config which sets only the things not set in the default one. For scope.sh and rifle.conf, ranger reads either the user’s or the global config.

The best practice is to only add the options/keybindings you actually want to change to your rc.conf, rather than to have a complete copy of the default rc.conf. This eliminates the need to update your config manually and gives you the benefits from new options/keybindings of future ranger versions. If you want to keep the full rc.conf though, you may want to set the environment variable RANGER_LOAD_DEFAULT_RC to FALSE to avoid loading both the default and your own rc.conf. In this case you have to update your config manually though.