Vim: ranger setup

Ranger is an interesting alternative to NerdTree on Vim. I’ve found it easier and more intuitive to navigate the directories and execute commands on them than nerdtree, but it lacks the possibility to show the working tree directly on the active buffer. It’s as well vim-motion-based and light weight.

ranger file browser   " ranger " Compatible with ranger 1.4.2 through 1.7.* " Add ranger as a file chooser in vim " If you add this code to the .vimrc, ranger can be started using the command " ":RangerChooser" or the keybinding "<leader>r". Once you select one or more " files, press enter and ranger will quit again and vim will open the selected " files. function! RangeChooser() let temp = tempname() " The option "--choosefiles" was added in ranger 1.5.1. Use the next line " with ranger 1.4.2 through 1.5.0 instead. " exec 'silent !ranger --choosefile=' . shellescape(temp) if has("gui_running") exec 'silent !xterm -e ranger --choosefiles=' . shellescape(temp) else exec 'silent !ranger --choosefiles=' . shellescape(temp) endif if !filereadable(temp) redraw! " Nothing to read. return endif let names = readfile(temp) if empty(names) redraw! " Nothing to open. return endif " Edit the first item. exec 'edit ' . fnameescape(names[0]) " Add any remaning items to the arg list/buffer list. for name in names[1:] exec 'argadd ' . fnameescape(name) endfor redraw! endfunction command! -bar RangerChooser call RangeChooser() nnoremap <leader>r :<C-U>RangerChooser<CR> Source: ""