8

I have installed Dr. Chip's netrw from his homepage, since it is newer and more often updated than the files that are part of the main Vim distribution.

Before Vim 8 I always sued the Vimball install method, by opening the .vba and running :source %. But, now that Vim 8 added the packages mechanism I decided to use that. I have my packages under:

~/.vim/pack/packages/start/
~/.vim/pack/packages/opt/

So to install NETRW as a package I did:

cd ~/.vim/pack/packages/start/
wget  http://www.drchip.org/astronaut/vim/vbafiles/netrw.vba.gz
mkdir netrw.vim
gunzip netrw.vba.gz
vim netrw.vba
:UseVimball ~/.vim/pack/packages/start/netrw.vim

And it installed correctly. But now when I edit a file and use a netrw command, say, :Lexplore I'm not sure which netrw is being used. If I do:

vim foo
:scriptnames
  1: /etc/vimrc
  2: /usr/share/vim/vimfiles/archlinux.vim
  3: ~/.vim/vimrc
  (...)
 20: /usr/share/vim/vim80/plugin/netrwPlugin.vim
 21: /usr/share/vim/vim80/plugin/rrhelper.vim
 22: /usr/share/vim/vim80/plugin/spellfile.vim
 23: /usr/share/vim/vim80/plugin/tarPlugin.vim
 24: /usr/share/vim/vim80/plugin/tohtml.vim
 25: /usr/share/vim/vim80/plugin/vimballPlugin.vim
 26: /usr/share/vim/vim80/plugin/zipPlugin.vim
 27: ~/.vim/pack/packages/start/csv.vim/plugin/csv.vim
 28: ~/.vim/pack/packages/start/csv.vim/ftdetect/csv.vim
 29: ~/.vim/pack/packages/start/netrw.vim/plugin/netrwPlugin.vim
 30: /usr/share/vim/vim80/scripts.vim

So the distribution netrw runs first (20) and then runs the installed one (29). If I add packloadall to my vimrc the situation changes:

  1: /etc/vimrc
  2: /usr/share/vim/vimfiles/archlinux.vim
  3: ~/.vim/vimrc
  4: ~/.vim/pack/packages/start/csv.vim/plugin/csv.vim
  5: ~/.vim/pack/packages/start/netrw.vim/plugin/netrwPlugin.vim
  (...)
 19: /usr/share/vim/vim80/plugin/gzip.vim
 20: /usr/share/vim/vim80/plugin/logiPat.vim
 21: /usr/share/vim/vim80/plugin/manpager.vim
 22: /usr/share/vim/vim80/plugin/matchparen.vim
 23: /usr/share/vim/vim80/plugin/netrwPlugin.vim

And the installed netrw in my directory runs first (5). Yet, the Vim distribution netrw still runs (23)!

  • Which netrw will Vim use when I do, say, :Lexplore? It appears to use the new (Vimball installed one) for :Lexplore but I'm not sure since :h pi_netrw gives me the new document, but :h netrw gives me the old documentation (the one that comes with Vim).

  • Running :helptags ~/.vim/pack/packages/start/netrw.vim/doc does not help with the documentation problem above (i.e. I get sometimes the new one and sometimes the old one). Is there something I'm doing wrong with this?

  • Does Vim always give preference to plugins/scripts/autoload commands that are in $VIM (default ~/.vim) above the ones in $VIMRUNTIME?

1
  • 1
    If you want to be sure that you have only one version of netrw installed, you can use the NetrwClean plugin to remove all versions of netrw (the one in your user directory ~/.vim and the one in the system directory /usr/share/vim). Then you can reinstall the newest version of netrw from Dr. Chip's website, and you are sure that only this version will be running now.
    – weibeld
    May 25, 2019 at 16:08

1 Answer 1

4

If you look at netrwPlugin.vim you'll find:

if &cp || exists("g:loaded_netrwPlugin")
 finish
endif

So just set this in your .vimrc:

let g:loaded_netrwPlugin = 1

If they both use the same variable (g:loaded_netrwPlugin) then they only one can be loaded and it is sufficient to either use packloadall or source ~/.vim/pack/packages/start/netrw.vim/plugin/netrwPlugin.vim at the end of your .vimrc.

3
  • 1
    But then it also won't load the netrw from ~/.vim/pack/../netrw? Mar 2, 2017 at 12:25
  • @Carpetsmoker right, updated
    – laktak
    Mar 2, 2017 at 16:07
  • 1
    You're right, both use the same variable. And even more, they set the variable to the version of the plugin being loaded, which allows to test which file is in operation. I still wonder how I fix the documentation tags but that should be another question. Many thanks!
    – grochmal
    Mar 2, 2017 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.