Vifm is a terminal file manager for linux that relies heavily on vim-like keybindings. Overall it is quite fast and feature-full, making it a prominent choice among minimalist users. Below I mention some steps I have taken to make it more useful.

Most of these require modifying only the VIFM config file. A good place to find/create such a file is ~/.config/vifm/vifmrc. If this file already exists on your machine, create a backup of the file, because we will be editing it. Now delete all contents from the original file (not the backup), and start with an empty vifmrc file. If you do not have such a file at that location, create an empty file with that name.

Coloured file/folder preview and suggestions

VIFM, by default, has a left pane and a right pane. I have found that it is best to use the left pane as the standard file browser, and the right panel as a preview for the file/folder currently under the cursor. That is enable by the following command:

" show file and directory preview in right pane
view!
" preview text files using "man"
fileviewer {*.[1-8]},<text/troff> man ./%c | col -b

This runs at startup and forces VIFM to use the right panel for preview. The second command tells VIFM to use the man command for preview text files. We can improve this by introducing multiple colours in the folder preview.

" enable ls colors in folder preview
fileviewer */ ls --color=always
fileviewer .*/ ls --color=always

The two commands together instruct VIFM to use the shell command ls --color=always as a folder previewer. The resultant view is shown in the image below.

Enabling suggestions

The functionality of the right panel can be improved by enabling suggestions in the right panel.

" what to suggest on the right pane
set suggestoptions=normal,visual,view,otherpane,keys,marks,registers

You might have set the keybinding dd to delete a file, but you have forgotten whether it was dd or dD. The above setting makes it easy to recall these bindings: if you press ‘d’, the right panel will show all keybinding sequences that start with ‘d’, allowing the user to refresh their memory. Besides keybindings, it also shows all the marks that you have defined. For example, you might have forgotten whether you have marked your work folder to ‘w’ or ‘W’. On pressing ', the right panel will show all the marks that you have defined in the vifmrc, making it easy to use the marks. This is shown in the image below.

Using tabs more efficiently

We often find it convenient to work simultaneously with multiple directories/views. This is where tabs become useful; you can have your work folder open in one tab and your downloads folder open in another tab, and copy files easily from one to the other. In order to make this process easy, insert the following lines in your vimrc.

" create new tab
nnoremap <c-t> :tabnew<cr>:view!<cr>

" switch to tab to the left
nnoremap H :tabprevious<cr>:view!<cr>

" switch to tab to the left
nnoremap L :tabnext<cr>:view!<cr>

" switch to tab to the left
nnoremap Q :q<cr>

The mappings, respectively, mean that you can use CTRL+t to create a new tab, H to switch to the tab on the left, L to switch to the tab on the right, and Q to close to the current tab.

Trash folder for safer deletion

For safer delete operators, we enable the trash setting and set a trash folder.

" enable trash and set trash folder
set trash
set trashdir=~/.local/share/Trash/files

If the folder mentioned in the last setting does not exist, you have to create it. Once this is done, any file/folder that is deleted using the default dd keybinding actually goes into the trash folder, and can be restored later. Permanent deletion can be performed through the more distant keybinding DD, to ensure that it does not happen accidentally. We can also remove the confirmation dialog that appears whenever we want to trash/delete a file.

" remove confirmation before trash/delete
set confirm-=delete,permdelete

Customise the statusline

The bottom of the VIFM window shows a statusline where various pieces of information can be displayed. I prefer a simplistic status, where I show the filename at the left end (%t), the current file size (%20s) after that, then the file modification date (%-30d), and finally the remaining storage on the file-system (%a). The numbers represent the width of the blocks.

" set format of statusline
set statusline="%t %20s %= %-30d %a"

The format of the modification date can be set in the following way:

" set format of file modification time
set timefmt='%b %d, %Y @ %H:%M'

The resultant statusline is shown in the image below.

Marks can be used as favourite folders to reach them quickly. They are defined in the following manner:

mark h ~/
mark d ~/Downloads/
mark c ~/.config/

Inserting these lines into the vifmrc defines three marks corresponding to the three specified folders. Upon starting vifm, you can now press, say, '+d to change into the Downloads folder. Same holds for the other marks. This provides a very fast method of accessing commonly used folders.

Fuzzy search using fzf

It is easier to search files using a fuzzy finder like fzf. After installing the fzf binary (look up how you can do this in your specific distribution), fuzzy finding can be integrated into VIFM using the following lines:

" use fzf to fuzzy search and run file
command! FZFfind : set noquickview
                \| let $FZF_PICK = term('find ./* | fzf --height 10 2>/dev/tty')
                \| if $FZF_PICK != ''
                \|     execute 'goto' fnameescape($FZF_PICK)
                \| endif
nnoremap / :FZFfind<cr>

The above search is triggered by the keybinding /. It lists all files in the present directory and further down in the subdirectories and allows searching according to the provided prompt. The file that is selected (by pressing Enter) is executed.

Miscellaneous options

There are several settings which also help to be enabled. These are listed below.

" useful options
set syscalls dotfiles wildmenu wildstyle=popup
set history=100 undolevels=100 followlinks norunexec
set ignorecase smartcase nohlsearch incsearch
  • syscalls instructs VIFM to use its internal methods for copy/paste operations rather than using utilities like cp.
  • dotfiles makes the hidden files and folders visible in VIFM.
  • wildmenu and wildstyle improve the way in which completion is shown for commands.
  • history sets the maximum number of operations stored in history. undolevels sets the maximum number of actions that can be undone.
  • followlinks means that clicking on a link directs you to the target. norunexec means clicking on executable files will not automatically execute them.
  • ignorecase and smartcase mean that search operations are case-insensitive unless there is at least one uppercase character.
  • nohlsearch and incsearch mean that the search will be incremental and search results will not be selected before enter is pressed.

Keybindings to copy file name, etc

It is very useful to set keybindings for common operations like copying the path of the parent directory, name of the current file under the cursor, and the full path of the current file. Through the commands below, these can be done with the keybindings yd, yn and yp respectively.

" copy parent directory path to clipboard
nnoremap yd :!echo %d %i | xclip -i -r -selection 'clipboard' -f 
            \| xclip -i -r -selection 'primary'<cr>
" copy current file name to clipboard
nnoremap yn :!echo %c %i | xclip -i -r -selection 'clipboard' -f 
            \| xclip -i -r -selection 'primary'<cr>
" copy current file full path to clipboard
nnoremap yp :!echo %c:p %i | xclip -i -r -selection 'clipboard' -f 
            \| xclip -i -r -selection 'primary'<cr>

Creating new files and folders

The first command below sets t as the key to wait for a filename, and then creates an empty file with the name on pressing enter. The second command similarly does the same for a new folder, but with the key M.

" mapping to create new blank file
nnoremap t :touch<space>

" mapping to create new folder
nnoremap M :mkdir<space>

The directory creation is shown in the image below (notice the :mkdir at the bottom).

Starting a shell or a terminal

" mapping to open shell in pwd
nnoremap S :shell<cr>

" mapping to start terminal
nnoremap <a-t> :!$TERMINAL &<cr>

S starts a shell in the current directory. ALT+t spawns a new terminal by executing the environment variable $TERMINAL. Since I use the simple terminal st, mine is set to TERMINAL=st in my .bashrc file. A spawned terminal is shown in the image below.

Keybindings for fast rename

The two commands below allow renaming files quickly, by pressing a or A. The latter skips the extension and allows renaming only the basename, since that is what we typically do. The latter allows changing the entire filename, including the extension.

" rename without extension
nnoremap a cW 
" rename with extension
nnoremap A cw

We often have to select multiple files in a range, for copy or move operations. The two commands below make this easier: SPACE selects one file and then moves the cursor down by one file, allowing us to press SPACE again immediately to select the next file. T does the same thing, but from bottom to top.

" mapping to toggle select and move down
nnoremap <space> tj
" mapping to move up and toggle select
nnoremap T kt

An example of a selection is shown in the image below.

That’s all.