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?
Best Answer
Central configuration
If it's okay to configure the local exceptions centrally, you can put such autocmds into your
~/.vimrc
: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
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
.