Ranger a terminal browser for Vim

Written by | 8 minutes read | Tags vim, tool | Comments

Ranger is a file manager with VI key bindings. It provides a minimalistic and nice curses interface with a view on the directory hierarchy. I stumbled upon this tool during a vimberlin meetup.

(This article has been tested with NVIM v0.2.2, Vim 8.0 with 1-692, and ranger 1.8.1)

Installation

Per package:

$ sudo apt-get install ranger

Or per source:

$ git clone git://git.savannah.nongnu.org/ranger.git /tmp/ranger && cd /tmp/ranger && git checkout v1.8.1 && sudo make install ```


## First start

```sh
$ ranger

https://farm5.staticflickr.com/4568/25153021168_e17079b38c_o_d.png

Miller columns of ranger

What you see are Miller columns, where the middle pane is the current directory, the left pane is the parent directory, and the right pane displays a preview for the file your are currently browser in the middle column. All in all it looks like Finder tool for Mac.

Text files are displayed with the less program. PDFs are converted to text for displaying preview and images are shown either with ASCII images or your default image viewer.

And get out of it via q.

Navigation shortcuts

Working with Files:

General shortcuts

Command interface

Customizing ranger

$ ranger --copy-config=all

It will create the rifle.conf, commands.py, commands_full.py, rc.conf, and scope.sh files in your ~/.config/ranger folder. rifle.conf is rangers file executor/opener.

E.g.:

#--------------------------------------------
# Audio without X
#-------------------------------------------
mime ^audio|ogg$, terminal, has mplayer  = mplayer -- "$@"
mime ^audio|ogg$, terminal, has mplayer2 = mplayer2 -- "$@"
mime ^audio|ogg$, terminal, has mpv      = mpv -- "$@"
ext midi?,        terminal, has wildmidi = wildmidi -- "$@"

commands_full.py defines commands for your rc.conf as well as terminal commands - if you want to create your own commands put them into commans.py. The scope.sh handles previews for ranger so that you can see the results of file in ranger instead of opening an external command.

rc.conf

Contains basic configuration like displaying hidden files and shortcuts

# Jumping around
map J     history_go -2
map K     history_go 0

Vim plugins for ranger

There are a bunch of plugins out there, which all uses Ranger in different ways:

The plugin author rafaqz pointed out the differences between his plugin and the one francoiscabrol:

So feel free to use the extension which best fits to your needs.

VCS awareness

Edit rc.conf:

# Be aware of version control systems and display information.
set vcs_aware true

# State of the three backends git, hg, bzr. The possible states are
# disabled, local (only show local info), enabled (show local and remote
# information).
set vcs_backend_git enabled
set vcs_backend_hg disabled
set vcs_backend_bzr disabled

You can read more about under the wiki VCS integration of Ranger. Be aware then loading a big repo may slow down opening ranger.

Links