Specific VIM Settings Per Project

From time to time, I contribute to several different projects and work with diverse teams. Naturally, every project and every team is different. This applies to code formatting as well - such as braces, tabs and tabstops. It can be a little clumsy to switch different coding styles, especially when working on several projects simultaneously. VIM can help you, anyway.

Override VIM Settings Per Folder

One nice little feature of good old VI is to allow configuration per folder. Everything you need to do is just place .exrc file in the current folder and kick off VI. This feature still exists with VIM, but is disabled by default. To enable it, just set exrc and VIM will respect custom configurations in current directory as well. VIM recognizes .vimrc files as well, so you're good to go with .vimrc as configuration file name.

Attention: Enabling exrc is dangerous. It is disabled by default for good reason. Since you can do pretty much everything within a VIM configuration file - including shell execution - it's highly recommended to use the exrc option only in pair with a second option which disables shell execution and write operations, called secure. Always append set secure when exrc option is enabled!

Put simply, just append the following lines at the end of your ~/.vimrc:

set exrc
set secure

and you're good to go. Now VIM will recognize and apply your custom project/folder settings. Enjoy.


(c) Copyright 1998 - 2014 Ilker Cetinkaya.