How to switch between multiple vim configurations with a command or local vimrc files?

I have this in $HOME/.vimrc:

if filereadable(".vim.custom")
    so .vim.custom

This allows me to put a .vim.custom file in every directory to load commands and options specific to that directory. If you’re working on multiple projects that have deep directory structures you might need something more sophisticated (e.g. walk up the directory tree until a .vim.custom is found), but the same basic idea will work.


I now do something like this in order to read a .vim file from the same directory as the file I’m editing, regardless of what the current directory is.

let b:thisdir=expand("%:p:h")
let b:vim=b:thisdir."/.vim"
if (filereadable(b:vim))
    execute "source ".b:vim

Leave a Comment