If you can, it’s a good idea to set up your .vimrc
file using
conditionals so that it’s compatible on all of the systems with which you
need to work. Using one .vimrc
file enables you to include it as part of a
centralised set of dotfiles that you can keep under version control.
However, if on a particular machine there’s a special case which means you need
to load some Vim directives for that machine, you can achieve this by way of a
local Vim file kept in .vimrc.local
, only on one particular machine, and
detecting its existence before attempting to load it in your master .vimrc
file with the following stanza:
if filereadable(glob("~/.vimrc.local"))
source ~/.vimrc.local
endif
As an example, on one of the nameservers that I manage, I wanted to make sure
that the correct filetype was loaded when editing zone files ending in .nz
or
.au
for New Zealand and Australian domains. The following line in
.vimrc.local
did the trick:
autocmd BufNewFile,BufRead *.au,*.nz set filetype=bindzone
If the .vimrc.local
file doesn’t exist on any particular machine, Vim will
simply not attempt to load it on startup.
Besides machine-specific code, this kind of setup may be advisable if you keep
secret or potentially sensitive information in your .vimrc
file that you
wouldn’t want published to a public version control tracker like GitHub, such
as API keys, usernames, machine hostnames, or network paths.