summary refs log blame commit diff stats
path: root/examples/vim_file_chooser.vim
blob: df3f50e556b8f1f45aa3505ed7c95c941b357d63 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
                                     
 












                                                                           
" Add ranger as a file chooser in vim
"
" If you add this function and the key binding to the .vimrc, ranger can be
" started using the keybinding ",r".  Once you select a file by pressing
" enter, ranger will quit again and vim will open the selected file.

fun! RangerChooser()
    exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h")
    if filereadable('/tmp/chosenfile')
        exec 'edit ' . system('cat /tmp/chosenfile')
        call system('rm /tmp/chosenfile')
    endif
    redraw!
endfun
map ,r :call RangerChooser()<CR>