I had a look at how
Dirvish did it, and tested this:
au VimEnter * sil! au! FileExplorer *
au BufEnter * if s:isdir(expand('%')) | bd | exe 'Ranger' | endif
fu! s:isdir(dir) abort
return !empty(a:dir) && (isdirectory(a:dir) ||
\ (!empty($SYSTEMDRIVE) && isdirectory('/'.tolower($SYSTEMDRIVE).a:dir)))
It seems to work but I don't know how reliable it is.
s:isdir() is a function which tests whether the path of the current buffer matches a directory.
VimEnter autocmd seems to get rid of
BufEnter autocmd deletes the buffer (if you want to wipe it completely, replace
bw), then calls the
ranger file manager.
Dirvish plugin, before calling the
:Dirvish command, the
BufEnter autocmd redraws the screen and echo an empty string (
redraw | echo ''). I don't know why it does this, so I didn't copied it, but if you have some issue (maybe with rendering artifacts, sometimes
:redraw! is used to get rid of them), try to add these commands back:
au BufEnter * if s:isdir(expand('%'))
\| bd | redraw | echo '' | exe 'Ranger' | endif