发布于 

终端文件管理器 ranger 入门

Ranger is a file manager with text-based user interface for Unix-like systems.

更新:

Joshutoranger-like terminal file manager written in Rust.

ranger 是用 Python 写的,joshuto 是用 Rust 重写的,速度更快


操作

  • jk 下(切换当前文件夹文件)

  • [] 下(切换上一层文件夹)

  • h 左(进入文件夹或打开文件)

  • l 右(返回上一层)

  • : 启动命令行

  • Esc 退出命令行

  • r 输入打开文件的方式

  • zh 显示隐藏文件

  • zf 过滤文件

  • q 退出 ranger

  • gg 跳到当前文件夹最上面

  • Shift + G 跳到当前文件夹最下面

  • Shift + h 跳到上一条操作历史记录

  • Shift + l 跳到下一条操作历史记录

  • om / oM 按文件名排序

  • os 按文件大小排序

  • oc 按修改日期排序,文件夹默认是按文件名排序

  • / 搜索

  • n 下一个搜索结果

  • N 上一个搜索结果

  • Shift + s 在此文件夹位置打开终端

  • yp 复制当前文件路径

  • yn 复制文件名

  • y 复制去掉后缀的文件名

  • cw 重命名文件

  • i 在文件名前开始重命名

  • a 在文件后缀前开始重命名

  • A 在文件后缀后开始重命名

  • 文件操作

    • v 批量选中文件,后可执行批量复制文件名、重命名等操作

    • yy 复制文件

    • dd 剪切文件

    • pp 粘贴文件

    • po 覆盖文件

    • dD 删除文件

    • du 查看文件夹大小

配置

执行 ranger --copy-config=all 生成默认配置文件:

1
2
3
4
5
6
7
8
9
creating: /Users/hcj/.config/ranger/rifle.conf
creating: /Users/hcj/.config/ranger/commands.py
creating: /Users/hcj/.config/ranger/commands_full.py
creating: /Users/hcj/.config/ranger/rc.conf
creating: /Users/hcj/.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.

将 ranger 的默认编辑器配置成 neovim

编辑 ~/.config/ranger/rifle.conf

1
2
3
4
5
# Define the "editor" for text files as first action
mime ^text, label editor = $EDITOR -- "$@"
mime ^text, label pager = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = $EDITOR -- "$@"
!mime ^text, label pager, ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"

$EDITOR 修改成 nvim, 如下:

1
2
3
4
5
6
# Define the "editor" for text files as first action
mime ^text, label editor = nvim -- "$@"
mime ^text, label pager = "$PAGER" -- "$@"
!mime ^text, label editor, ext xml|json|csv|tex|py|pl|rb|js|sh|php = nvim -- "$@"
!mime ^text, label pager, ext xml|json|csv|tex|py|pl|rb|js|sh|php = "$PAGER" -- "$@"

插件

Ranger Devicons plugin

使用前需要安装 nerd-fonts 字体并在终端设置,否则图标无法显示,macOS 下为:

1
2
brew tap homebrew/cask-fonts
brew cask install font-hack-nerd-font

安装玩字体后,在 iTerm2 中设置字体:

Image Previews (图片预览)

需先安装 w3m 浏览器 :`brew install w3m`,打开配置文件 ` ~/.config/ranger/rc.conf` ,搜索修改:
1
2
set preview_images true
set preview_images_method iterm2