Baptiste Fontaine’s Blog  (back to the website)

Local .vimrc's

I discovered a great feature in Vim today. While we generally use the same Vim settings everywhere, we sometimes (have to) contribute to projects with a coding style different of ours, and because nobody wants to edit their .vimrc everytime to switch between configurations, Vim allows you to have per project .vimrc’s.

This feature can be enabled with one line in your .vimrc:

set exrc

When you start Vim, it begins by looking at some predefined locations for a configuration file (the first one is $HOME/.vimrc). The exrc option, disabled by default, tell to Vim to not only load your personal .vimrc, but also to look in the current directory to check if there’s another .vimrc file, which will be loaded after your personal one. You can then use it to override your settings and/or add specific ones for this directory.

Additionally, if you share the local .vimrc with others (e.g. in a Git repository), you may want to set the secure option at the end of your personal .vimrc:

set secure

This disallow shell and write commands in the .vimrc of the local directory. On unix-like OSes, this option is set by default if you’re not the owner of the file.

For more Vim gems, check my .vimrc on GitHub!