1 " Compatible with ranger 1.4.2 through 1.7.*
3 " Add ranger as a file chooser in vim
5 " If you add this code to the .vimrc, ranger can be started using the command
6 " ":RangerChooser" or the keybinding "<leader>r". Once you select one or more
7 " files, press enter and ranger will quit again and vim will open the selected
10 function! RangeChooser()
12 " The option "--choosefiles" was added in ranger 1.5.1. Use the next line
13 " with ranger 1.4.2 through 1.5.0 instead.
14 "exec 'silent !ranger --choosefile=' . shellescape(temp)
15 exec 'silent !ranger --choosefiles=' . shellescape(temp)
16 if !filereadable(temp)
21 let names = readfile(temp)
27 " Edit the first item.
28 exec 'edit ' . fnameescape(names[0])
29 " Add any remaning items to the arg list/buffer list.
31 exec 'argadd ' . fnameescape(name)
35 command! -bar RangerChooser call RangeChooser()
36 nnoremap <leader>r :<C-U>RangerChooser<CR>