2

I'm using Vim for a project that has a lot of pages per chapter, and Vim is a little bit slow. I want to create a local '.vimrc' file for this project with only the plugins I need, and I'm trying to understand when to use the "set exrc" option and local '.vimrc' files in Vim, and how to manage plugins with multiple 'vimrc' files. I understand that "set exrc" allows Vim to look for '.vimrc' files in the current directory and execute the commands in those files, and that local '.vimrc' files can be used to set project-specific settings in Vim.

My question is, when should I use "set exrc" in my standard 'vimrc' file, and when should I use a local '.vimrc' file in a specific directory? And how should I manage plugins with multiple 'vimrc' files, given that running the 'PlugUpdate' and 'PlugClean' commands in one 'vimrc' file may affect plugins listed in other 'vimrc' files?

Also, when I start Vim with a local '.vimrc' file, does it create a separate instance of Vim with its own set of plugins, settings, and configurations that are specific to the project or directory, or does it affect the standard 'vimrc' file and the plugins installed there?

I'm unsure when to use each of these options, and I would really appreciate a straight-forward answer to these questions, especially in the context of a large project with many pages per chapter.

1
  • Note that Neovim has a feature that only runs exrc files that have been manually marked as trusted. Vim does not have this feature, which makes Vim's exrc implementation insecure.
    – Flimm
    Commented Jul 5 at 8:30

1 Answer 1

5

First, set exrc is a prerequisite for using a local vimrc.

Second, assuming :help 'exrc' is enabled, your local vimrc is only read at startup, if you start Vim in the directory where you put it. Basically, starting Vim at the root of the project and :cd-ing around won't source any local vimrc.

Third, whether you have a local vimrc or not, your main vimrc is still sourced anyway so a local vimrc is not to be considered as an "alternative" vimrc, but as complementary vimrc.

Now…

when should I use "set exrc" in my standard 'vimrc' file

You set exrc if (not when) you need the ability to have local vimrcs.

and when should I use a local '.vimrc' file in a specific directory?

You create a local vimrc if (not when) you need it. Having specific settings applied for a specific context on top of your main settings is the usual justification.

And how should I manage plugins with multiple 'vimrc' files, given that running the 'PlugUpdate' and 'PlugClean' commands in one 'vimrc' file may affect plugins listed in other 'vimrc' files?

set exrc gives you the ability to source a local vimrc in addition to your main vimrc but it doesn't give you a separate runtime directory for installing your plugins and whatnot. This means that plugin management can only realistically happen in your main vimrc.

when I start Vim with a local '.vimrc' file, does it create a separate instance of Vim with its own set of plugins, settings, and configurations that are specific to the project or directory, or does it affect the standard 'vimrc' file and the plugins installed there?

No.

As mentioned in :help 'exrc', using that feature is not recommended. The suggested autocommand-based approach is a much better idea.

But you are being pretty vague. If you want actionable advice I would suggest you open a separate question where you explain your exact requirements and provide your full config.

1
  • Thanks. I will open another post to be more specific.
    – Mafsi
    Commented Mar 13, 2023 at 12:05

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.