I had a look at how Dirvish
did it, and tested this:
augroup ranger
au!
au VimEnter * sil! au! FileExplorer *
au BufEnter * if s:isdir(expand('%')) | bd | exe 'Ranger' | endif
augroup END
fu! s:isdir(dir) abort
return !empty(a:dir) && (isdirectory(a:dir) ||
\ (!empty($SYSTEMDRIVE) && isdirectory('/'.tolower($SYSTEMDRIVE[0]).a:dir)))
endfu
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.
The VimEnter
autocmd seems to get rid of netrw
.
The BufEnter
autocmd deletes the buffer (if you want to wipe it completely, replace bd
with bw
), then calls the ranger
file manager.
In the 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