Vim Configuration Files by Directory
I have Vim line numbers enabled (:set nu
) as a default, but I was working on a project recently where the line numbers weren't helpful. I wanted to disable them in that directory only, without changing my default setting.
One way to do this is to enable a local Vim configuration file. Here's how you do that:
" ~/.vimrc
set exrc
This enables the reading of .vimrc
in the current directory.
Caveat: you should also add the following:
" ~/.vimrc
set secure
When this setting is enabled, :autocmd
, shell, and write commands are not allowed in your local .vimrc
.
Enabling local Vim configurations give a lot of power to any local configuration file. For instance, you could clone a Git repo with a checked-in .vimrc
, and if you open Vim in that directory, any commands in that configuration will be executed. Use with caution.
More info:
:help 'exrc'
:help 'secure'
h/t Josh Branchaud
Tweet