Gain Productivity by Having Different Vim Settings for Every Project

Local .vimrc

Sometimes you just want to have vim configurations per project basis. Imagine how awesome it is to fire up vim with a different color scheme for each one of your projects. You might want to include special plugins for the Node.js project you are hacking on lately. Fortunately, this is extremely easy to accomplish.

Create a file called “vimrc-local.vim” in the ~/.vim/plugin/ directory. After that, put the following 5 lines of code in it:

1
2
3
4
5
" Do we have local vimrc?
if filereadable('.vimrc.local')
  " If so, go ahead and load it.
  source .vimrc.local
endif

Now you can put local vimrc file in any directory of your computer and vim will automatically load it for you. Don’t forget that you have to name the config file “.vimrc.local”. If you prefer a different name, you can replace .vimrc.local with your desired name in the script we just wrote.

1
2
3
$ cd path/to/project
$ ls .vimrc.local
$ mvim . # or vim, etc.

You might be curious what the local vimrc of Vim Ninjas looks like. Here it is:

1
2
3
4
5
6
7
8
" The awesome vividchalk color scheme
colorscheme vividchalk

" Check spelling
set spell

" Monaco 14
set guifont=Monaco:h14

Your editor might look and feel completely different depending on your current focus. Just a few lines of code and you are there. How cool is that?

About the author

Veselin Todorov is a software consultant focused on testing, code quality and building awesome products. He is helping companies to ship their products with confidence and style.

If you are passionate about JavaScript, Node.js, TDD, building and growing applications, you should visit his blog at RobustJS.com