Local Settings
If you’re like me then you have a centralised repository for Vim’s settings. There are situations, however, where local settings are required. For example, I may want subtly different settings when working on files on a server, but still want to load my preferred .vimrc
as well.
One way to solve this that I’ve seen used in dotfiles on GitHub is to source
a "local" settings file:
if filereadable('~/.vim/local.vim')
so ~/.vim/local.vim
endif
This snippet can be placed in your centralised .vimrc
, and then machines or accounts that require tailoring can be supported by creating a suitable ~/.vim/local.vim
file. In the other cases where this isn't required, filereadable
is used to prevent loading a non-existent file.
This concept can be extended to support project-specific configuration by checking for a settings file in the current directory:
if filereadable('.local.vim')
so .local.vim
endif
There are plugins that implement more elegant versions of this, including localvimrc by Markus Braun.