27
7
I'd like to modify my .vimrc
to read the value of a variable from an external file. How can I do this?
Specifically, a friend and I share a git repo with our .vim
files, but there are a few small differences in what we want in our configs. So most of the file is common, but we use if statements to determine whether to load user-specific sections, like this:
let whoami = "user2"
if whoami == "user1"
...
After checking our common .vimrc
out of source control, we each have to change the let whoami
assignment so our own section will be loaded. Instead, I'd like to keep a separate file, which can be different for each of us, and from which vim will load that variable value.
Maybe another angle on this is: Will vim automatically read all the files in my .vim
directory? If so, we could each put a symlink in there called username.vim, and link that to an external file that would be different for each of us.
2FYI - In my situation, it was helpful to do
let whoami = ""
right before thesource
line, so that if it fails to load the external file, the variable exists and I get the error message we had set up previously for the variable not being set. – Nathan Long – 2010-12-22T15:10:34.9932@GorillaSandwich: I use this to source my vimrc on my windows machine since windows doesn't have symbolic links. I have an SVN folder that contains this and all my other dot-files. So I just have an _vimrc that sources the real one in the svn folder. – Robert S Ciaccio – 2010-12-22T17:01:45.070
@GorillaSandwich: see my answer for the
silent! source
part – akira – 2010-12-23T07:25:29.533