Scripts2026年5月5日·1 分钟阅读

Ranger — Terminal File Manager with Vi Keybindings

Ranger is a console file manager with vi-style key bindings, file previews, and a multi-column directory layout that makes navigating and manipulating files fast without leaving the terminal.

Introduction

Ranger is a text-based file manager that uses a Miller columns layout (like macOS Finder column view) in the terminal. It is written in Python with vi-style keybindings, making it efficient for developers who already think in hjkl.

What Ranger Does

  • Displays directories in a three-column layout: parent, current, and preview
  • Provides file previews for text, images (via w3m/kitty/sixel), PDFs, and archives
  • Supports bulk rename, multi-file selection, tabs, and bookmarks
  • Integrates with external tools: rifle (opener), atool (archives), highlight (syntax)
  • Allows full customization via Python config files and plugins

Architecture Overview

Ranger is a single-threaded Python application using curses for terminal rendering. The file system is lazily loaded into an internal directory model. The rifle file opener uses a rule-based MIME config to dispatch files to the correct program. Previews are generated by scope.sh, a user-editable shell script.

Self-Hosting & Configuration

  • Install from PyPI (pip install ranger-fm) or system package manager
  • Generate default config with ranger --copy-config=all (creates rc.conf, rifle.conf, scope.sh)
  • Edit ~/.config/ranger/rc.conf to change keybindings, sorting, and display options
  • Customize file previews by editing scope.sh (add handlers for new file types)
  • Enable image previews by setting set preview_images true and choosing a method (kitty, ueberzug, w3m)

Key Features

  • Vi-native navigation: hjkl, gg, G, /, :commands
  • Tabs and bookmarks for quick directory switching
  • Bulk rename via :bulkrename which opens filenames in $EDITOR
  • Extensible with Python plugins (Git status, icons, archive mounting)
  • Trash support via integration with trash-cli

Comparison with Similar Tools

  • nnn — faster (written in C) and lighter, but minimal UI; less visual feedback
  • lf — Go rewrite inspired by Ranger; faster startup, fewer built-in features
  • Yazi — Rust-based, async I/O, faster for large dirs; newer with smaller plugin ecosystem
  • Midnight Commander (mc) — dual-pane orthodox style; different UX paradigm
  • Thunar/Nautilus — graphical file managers; require a desktop environment

FAQ

Q: Is Ranger slow on large directories? A: Python-based, so yes compared to C/Rust alternatives. For dirs with 10k+ files, consider nnn or Yazi.

Q: How do I enable file icons? A: Install the ranger_devicons plugin and a Nerd Font in your terminal.

Q: Can I use Ranger as a file picker for other apps? A: Yes. Use ranger --choosefile=/tmp/pick and read the selected path from that file.

Q: Does Ranger support Git integration? A: Via plugins. The built-in VCS integration shows git status indicators in the file list.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产