vimtricks.wiki Concise Vim tricks, one at a time.

How do I make Vim automatically load a project-specific configuration file from the project directory?

Answer

:set exrc secure

Explanation

Adding set exrc to your vimrc tells Vim to read a .vimrc file from the current working directory when it starts. This lets each project carry its own Vim settings — indentation, makeprg, path options, or any other local customization — without polluting your global config. Always pair it with set secure, which prevents the local config from running shell commands or mappings that could execute arbitrary code.

How it works

  • exrc — enables reading an extra .vimrc (or .nvimrc/.exrc) from the current directory at startup
  • secure — when set, the local vimrc can only set options and define mappings; it cannot run shell commands (:!), autocmds, or write commands

For Neovim, project-local Lua configs (.nvim.lua) are supported via the exrc option as well, and Neovim prompts you to trust the file before sourcing it.

Example

In your ~/.vimrc:

set exrc
set secure

In your project's .vimrc (at the project root):

set tabstop=2 shiftwidth=2 expandtab
set makeprg=cargo\ build
set path+=src/**

When you open Vim from that project root, these settings apply automatically for that project only.

Tips

  • Add .vimrc and .nvimrc to your global .gitignore so project-local configs are not accidentally committed
  • In Neovim, the exrc option with .nvim.lua triggers a trust prompt the first time; use :trust to explicitly allow a file
  • Use setlocal instead of set in your project vimrc to scope changes to the current buffer only

Next

How do I configure Vim's command-line tab completion to show all matches and complete to the longest common prefix?