gVIM breaks symlinks on windows?

I'm trying to keep my gVIM config in centralized place. For this, i have done

mklink c:\users\me\.vimrc c:\users\me\configs\_vimrc

That works fine until i change $MYVIMRC inside VIM. This instantly breaks symlink (c:\users\me.vimrc stop being a symlink and became ordinary file). Is it any way to fix this trange behavior? OS is Windows Vista with latest updates. gVIM is 7.2 from official site.


Solution 1:

Vim is supposed to handle this correctly by default. (:help backupcopy)

By default, on non-unix platforms, backupcopy is set to "auto". It will normally rename the file and write a new changed file when you save, but should modify the original file if the original file is a link or has a resource fork, etc.

Several possibilities:

  1. Your version of vim does not recognize the file is a symlink.
  2. You've set backupcopy or a related variable (breaksymlink?) to override default behavior.

I'd be surprised if it's 1, since you're dealing with a recent version of vim. Does this happen if you have an empty .vimrc?

Solution 2:

Try

mklink /J c:\users\me c:\users\me\configs

This will create a hardlink directory junction between c:\users\me and c:\users\me\configs that vista will respect when you rewrite you vimrc.

Solution 3:

The user xaizek suggested an workaround in the comments of a related question I asked: Symlink to .vimrc on windows makes file readonly upon write. Why?. I've adopted his solution, but made the $MYVIMRC assignment conditional because I use both Windows and OSX systems:

So, in my Windows ~/.vimrc file I have:

source /path/to/shared/vimrc

Then, in the shared .vimrc file I have:

if has("win32")
    let $MYVIMRC='~/path/to/shared/.vimrc'
endif