Ranger layer
Table of ContentsClose
1. Description
This layer brings Ranger features to spacemacs from the ranger package, with
optional dirvish integration.
To use this configuration layer, add it to your ~/.spacemacs. You will need to
add ranger to the existing dotspacemacs-configuration-layers list in this
file.
To use ranger/deer by default set ranger-override-dired to ranger/deer like
shown in the example below (setting this via customize as explained by the
original ranger installation instructions will not work). You can also use
dirvish for a modern dired experience; dired opens a single column, while
SPC a t r r opens dirvish with the full layout. To default with preview enabled
when entering ranger set ranger-show-preview to t. The following example code
shows how you can set both variables at once via the
dotspacemacs-configuration-layers of your dotfiles as follows:
(setq-default dotspacemacs-configuration-layers '(ranger :variables ranger-override-dired 'ranger ranger-show-preview t))
1.1. Features:
- use ranger to display dired with ranger like preview and stacked parent windows.
2. Configuration
Most parameters can be toggled on and off and stay within the current emacs session. Any settings that are desired on startup should be set below.
2.1. Customizing
Toggle the use of - to enter deer or ranger with ranger-enter-with-minus.
The possible values are:
'deer(default)'rangernil(restores the default behavior of-)
(setq ranger-enter-with-minus 'deer)
When disabling the mode you can choose to kill the buffers that were opened while browsing the directories.
(setq ranger-cleanup-on-disable t)
Or you can choose to kill the buffer just after you move to another entry in the dired buffer.
(setq ranger-cleanup-eagerly t)
You can choose to show dotfiles at ranger startup, toggled by zh
(setq ranger-show-hidden t)
Define custom function used to output header of primary ranger window. Must return a string that is placed in the header-line.
(setq ranger-header-func 'ranger-header-line)
Define custom function used to output header of parent and preview windows. Must return a string that is placed in the header-line.
(setq ranger-parent-header-func 'ranger-parent-header-line)
2.2. Dirvish options
Enable dired-omit-mode in dirvish buffers by default (layer variable):
(setq-default dotspacemacs-configuration-layers '(ranger :variables ranger-override-dired 'dirvish dirvish-enable-dired-omit t))
You can customize dirvish-attributes in your dotspacemacs/user-config:
(setq dirvish-attributes '(file-size file-time all-the-icons subtree-state vc-state))
See dirvish documentation for the full list.
A recommended mode-line format for dirvish (add to dotspacemacs/user-config):
(setq dirvish-mode-line-format '(:left (sort file-time " " file-size " " file-modes " " file-link-number) :right (omit yank index)))
2.3. Parent options
You can set the number of folders to nest to the left, adjusted by z- and z+
(setq ranger-parent-depth 2)
You can set the size of the parent windows as a fraction of the frame size
(setq ranger-width-parents 0.12)
When increasing number of nested parent folders, set max width as fraction of frame size to prevent filling up entire frame with parents.
(setq ranger-max-parent-width 0.12)
2.4. Preview options
You can choose to show previews literally, or through find-file, toggled by zi
(setq ranger-show-literal t)
You can set the size of the preview windows as a fraction of the frame size
(setq ranger-width-preview 0.55)
You probably don't want to open certain files like videos when using preview. To ignore certain files when moving over them you can customize the following to your liking:
(setq ranger-excluded-extensions '("mkv" "iso" "mp4" "bin" "exe" "msi"))
To set the max files size (in MB), set the following parameter:
(setq ranger-max-preview-size 10)
3. Key bindings
When ranger-override-dired is set to dirvish, the SPC a t r prefix is bound
to dirvish commands (e.g., SPC a t r r opens the full layout, SPC a t r d opens
dirvish in a single column).
| Key binding | Description |
|---|---|
SPC a t r r |
launch ranger / dirvish full layout |
SPC a t r d |
deer / dirvish single column |
f |
(ranger) search for file names |
C-p |
(ranger) toggle ranger in dired buffer |
j |
(ranger) navigate down |
k |
(ranger) navigate up |
yy |
(ranger) copy |
pp |
(ranger) paste |
R |
(ranger) rename |
D |
(ranger) delete |
C-j |
(ranger) scroll preview window down |
C-k |
(ranger) scroll preview window up |
i |
(ranger) show preview of current file |
zi |
(ranger) toggle showing literal / full-text previews |
zh |
(ranger) toggle showing dotfiles |
o |
(ranger) sort options |
H |
(ranger) search through history |
h |
(ranger) go up directory |
l |
(ranger) find file / enter directory |
RET |
(ranger) find file / enter directory |
q |
(ranger) quit |
;g |
(ranger) revert buffer |
z- |
(ranger) reduce number of parents |
z+ |
(ranger) increment number of parents |
C-SPC / TAB |
(ranger) mark current file |
v |
(ranger) toggle all marks |
t |
(ranger) toggle mark current file |
S |
(ranger) enter shell |
;C |
(ranger) copy directory / copy and move directory |
;+ |
(ranger) create directory |
Dirvish key bindings (when ranger-override-dired is dirvish):
| Key binding | Description |
|---|---|
q |
quit dirvish |
/ |
narrow |
TAB |
toggle subtree |
f / gf |
toggle layout (dirvish only) |
gt |
switch layout |
gd |
dispatch menu |
gl |
ls switches menu |