Open weirongxu opened 4 years ago
I know the vifm.vim
plugin has a replace_netrw
option to be used in conjunction with:
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
Don't know if that helps. https://github.com/vifm/vifm.vim/blob/master/doc/plugin/vifm-plugin.txt
NERDTree has a NERDTreeHijackNetrw
that I didn't know about, going to explore this to see if I can find a viable workaround using their approach... (ref: https://github.com/preservim/nerdtree/blob/30ad6da98482d8aee36d90c49711a8476b5e240a/plugin/NERD_tree.vim#L182)
I'm using this workaround to open coc-explorer when opening either a directory or no file specified. It also makes sure to change the directory to the specified directory (or current dir if no file specified). Hope it helps.
" CoC Explorer Settings
augroup MyCocExplorer
autocmd!
autocmd VimEnter * sil! au! F
" set window status line
autocmd FileType coc-explorer setl statusline=File-Explorer
"quit explorer whein it's the last
autocmd BufEnter * if (winnr("$") == 1 && &filetype == 'coc-explorer') | q | endif
" Make sure nothing opened in coc-explorer buffer
autocmd BufEnter * if bufname('#') =~# "\[coc-explorer\]-." && winnr('$') > 1 | b# | endif
" open if directory specified or if buffer empty
autocmd VimEnter * let d = expand('%:p')
\ | if argc() == 0
\ | exe 'CocCommand explorer --quit-on-open --position floating --sources buffer+,file+'
\ | elseif isdirectory(d) || (bufname()=='')
\ | silent! bd
\ | exe 'CocCommand explorer --quit-on-open --position floating --sources buffer+,file+ ' . d
\ | exe 'cd ' . d
\ | else
\ | cd %:p:h
\ | endif
" cd after open
autocmd User CocExplorerOpenPost let dir = getcwd() | call CocActionAsync("runCommand", "explorer.doAction", "closest", {"name": "cd", "args": [dir]})
augroup END
I know the
vifm.vim
plugin has areplace_netrw
option to be used in conjunction with:let g:loaded_netrw = 1 let g:loaded_netrwPlugin = 1
Don't know if that helps. https://github.com/vifm/vifm.vim/blob/master/doc/plugin/vifm-plugin.txt
This works like a charm! HOWEVER, vim-fugitive's :GBrowse
fails to open a link as it relies on netrw
to be automatically loaded with:
E117: Unknown function: netrw#NetrwBrowseX
I guess anything that depends on netrw
being loaded would fail.
EDIT: Found a solution on this issue: https://github.com/tpope/vim-fugitive/issues/1010
Just use:
let g:loaded_netrwPlugin = 1
so netrw
commands and mappings will be disabled and not all the autoloaded functions?
autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
I've adapted this for coc-explorer
:
" have vim start coc-explorer if vim started with folder
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'CocCommand explorer' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif
From https://github.com/preservim/nerdtree#how-can-i-open-nerdtree-automatically-when-vim-starts-up-on-opening-a-directory