Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use vim in many different contexts ... actually, probably most people do: There is the editing of configuration files, programming, documenting, email and so forth.

I very frequently found myself wishing for a facility that lets me put a vimrc into a directory and whenever I start vim from within that directory a local vimrc gets read as well to make context specific adaptions. For instance:

  • a vimrc in etc to implicitly set/release locks and create backups before/on write
  • a vimrc for each of my programming projects for (for example) project-specific indentation and frequently used macros, e.g. Debian patch signature
  • a vimrc in every documentation directory for the docs language specific settings (spellcheck!)

This would not only help me myself, but also enable me/us to share project and task specific settings among many users in each of the described situations and ahve the configuration with the context where we want it applied.

This seems very sensible to me and not too difficult to have/implement. Does anybody know of a vim plugin or have a config that honors vimrc files found within working directories?

share|improve this question
up vote 6 down vote accepted

Central configuration

If it's okay to configure the local exceptions centrally, you can put such autocmds into your ~/.vimrc:

:autocmd BufRead,BufNewFile /path/to/dir/* setlocal ts=4 sw=4

On the other hand, if you want the specific configuration stored with the project (and don't want to embed this in all files via modelines), you have the following two options:

Local config with built-in functionality

If you always start Vim from the project root directory, the built-in

:set exrc

enables the reading of a .vimrc file from the current directory. You can place the :set ts=4 sw=4 commands in there.

Local config through plugin

Otherwise, you need the help of a plugin; there are several on vim.org; I can recommend the localrc plugin, which even allows local filetype-specific configuration.

Note that reading configuration from the file system has security implications; you may want to :set secure.

share|improve this answer
exrc works perfectly. I will check out localrc for more refined use cases. – Bananguin Jun 18 '13 at 16:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.