Do you wish .vimrc
were more modular?
Often times I need a project specific Vim configuration, whether it’s just a indentation/whitespace configuration (btw check out editorconfig/editorconfig-vim for .editorconfig
support), or setting up project specific makeprg and build tools, or simply loading a project specific set of plugins. To solve this problem, I have initially had a project specific clone of the .vimrc
file, but have soon realized that there is a lot of code duplication, and that these files could be much more concise if there was a way to cascade the settings from multiple .vimrc
files.
So I’ve created this little snippet, and put it in my main .vimrc
file (or ~/.config/nvim/init.vim
if you prefer NeoVim):
{% include_code “Autoload .vimrc files” “vim” autoload_vimrc.vim %}
This script simply looks for all the .vimrc
files in parent’s subdirectories and sources them all. Since it starts from the root folder (or from $HOME
) and works its way to the current directory, it favours the most recent .vimrc
files allowing them to override any settings previously set by any .vimrc
that are higher in the directory structure. As a bonus, it also loads the tags files in the same way, because my setup is weird that way.
This allows me to have a global .vimrc
file in my $HOME
directory, then another one for my personal projects $HOME/projects/.vimrc
, and even one that is more specific for a node.js
project $HOME/projects/frontend/.vimrc
, and then some React specific config for my React projects in $HOME/projects/frontend/react/.vimrc
etc. You get the idea.
This comes in really handy if you need to load a different set of plugins for each of your projects, or have project specific Ultisnips snippets, or simply want to share a minimal .vimrc
config with other team members for this one specific project.
You can install it from ArtBIT/vim-modularvimrc.
Let me know what you think @artbit.