2

I wonder why netrw (:Explore) is not loaded after starting vim using vim -u NONE.

Inspecting my runtimepath yields: /Users/shuz/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim/vimfiles/after,/Users/shuz/.vim/after

, so common Vim directories are indeed present in the runtimepath.

If not the runtimepath, what mechanism causes netrw to be loaded?

2 Answers 2

4

netrw is a plugin, just one that is distributed with vim itself. For me, :Explore and friends are defined in /usr/local/share/vim/vim82/plugin/netrwPlugin.vim.

From the load-plugins section of :h initialization, step 4:

  1. Load the plugin scripts.

This does the same as the command:

:runtime! plugin/**/*.vim

The result is that all directories in the 'runtimepath' option will be searched for the "plugin" sub-directory and all files ending in ".vim" will be sourced (in alphabetical order per directory), also in subdirectories. However, directories in 'runtimepath' ending in "after" are skipped here and only loaded after packages, see below. Loading plugins won't be done when:

  • The 'loadplugins' option was reset in a vimrc file.
  • The |--noplugin| command line argument is used.
  • The |--clean| command line argument is used.
  • The "-u NONE" command line argument is used |-u|.
  • When Vim was compiled without the |+eval| feature.

Therefore, netrw is not loaded with -u NONE.

2
  • Thank you. Do you know why :Explore isn't loaded after executing :runtime! plugin/**/*.vim after starting Vim as vim -u NONE?
    – Shuzheng
    Commented Feb 24, 2021 at 12:52
  • That's because if you look at the first few uncommented lines of netrwPlugin.vim, it doesn't load the plugin if compatible is set (the default). It will load if you do vim -u NONE, then :set nocompatible | runtime! plugin/**/*.vim. Of course, whether or not that's the right thing to do depends on what you are ultimately trying to achieve. Commented Feb 24, 2021 at 13:21
0

You also need nocompatible to be set. That's usually the default, but not for -u NONE or -u empty-vimrc.

echo '' > empty-vimrc

# These do work
vim -u empty-vimrc -N .                       # sets nocompatible via -N
vim -u empty-vimrc --cmd 'set nocompatible' . # sets nocompatible before vimrc is loaded

# These don't work
vim -u empty-vimrc -c 'set nocompatible' .    # sets nocompatible after vimrc is loaded, too late
vim -u NONE --cmd 'set nocompatible' .        # -u NONE never works, as pointed out in previous answer
1
  • 1
    In many shells you could also write vim -u <(echo) or use -u NORC
    – D. Ben Knoble
    Commented Mar 20 at 15:14

Your Answer

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

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