I wish to store my Mac, Windows and Linux vim configuration files in git. On *nix systems, your vim configuration files go in ${HOME}/.vim but for the Windows binary, the same directory is named "vimfiles" Can I configure git to accommodate the different directory name?
You don't need to configure Git, just tell Vim to use ~/.vim
for Windows, too, by putting the following fragment into your ~/.vimrc
:
" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
" across (heterogeneous) systems easier.
if has('win32') || has('win64')
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
endif
My setup is very simple.
On Mac, the versioned directory is:
/Users/username/.vim
On Linux, it is:
/home/username/.vim
On Windows XP (yes), it is:
C:\Documents and Settings\username\vimfiles
They all point to the same GitHub repository.
My settings are stored in a vimrc
(no .
or _
) file located at the root of the repository. Therefore its versioned and commited/pushed/pulled like all the rest.
The actual default user-specific vimrc
,
/Users/username/.vimrc
/home/username/.vimrc
C:\Documents and Settings\username\_vimrc
is a real file, no need for a symlink. It contains only one line:
runtime vimrc
that tells vim to read, and execute, my vimrc
.
Because of how :runtime
works, I don't need to use a real absolute path which would be different on Unix-like platforms and on Windows.
Setting up a new machine or user is as simple as cloning my repo and typing two easy to remember words.
I also need to share config files for vim and other applications between multiple systems, and I found that git was not only overkill but also required manual syncing on each system to get the latest updates and to publish changes. A better solution for me is to put these config files into Dropbox, make all of my systems connect to my Dropbox account, and create symbolic links to these shared files.
For example, I put my vimrc file under Dropbox/conf/vimrc
, and then did
ln -s ~/Dropbox/conf/vimrc ~/.vimrc
You should be able to use Windows' mklink
to similar effect to create a _vimrc
symlink to that same file. In the same way, a common Dropbox/conf/vim
directory could be linked to locally as .vim
or .vimfiles
or whatever your OS' vim executable prefers.
Dropbox keeps a history of changes over the last 30 days, which is enough to handle recovering from most problems for which I needed git. The cool thing is that you can add that new macro or setting to your .vimrc
and it is automatically available on all your systems.
Of course this approach is also handy for your other config files, too (.gitconfig
, .gitignore
, .bashrc
, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With