Vim doesn’t load symlinked .vimrc

symbolic-linkvimzsh

I've got a symlinked .vimrc:

simont@charmander ~/repositories/config-files [master *]
± $ ls -l ~/.vimrc
lrwxr-xr-x  1 simont  admin  6  9 May 17:14 /Users/simont/.vimrc -> .vimrc

However, vim doesn't load it on startup.

When I run :echo $MYVIMRC from vim, it returns empty.

I'm not using any alias' for vim:

simont@charmander ~/repositories/config-files [master *]
± $ alias | grep vim

simont@charmander ~/repositories/config-files [master *]

There's a bunch of questions that seem to suggest that this should be working for me. Is there a particular flag I should pass to vim on startup to get it to follow symlinks? I'm stumped.

Best Answer

Symlink targets can be either absolute (starting with /) or relative to the symlink's location. Since the symlink is located in /Users/simont/ and has ".vimrc" as its target, it is essentially pointing to itself.

Try recreating the symlink using a correct path:

  • Relative (important: will be stored in the symlink exactly as given in command line, without considering $PWD at all):

    ln -sf repositories/config-files/.vimrc ~/.vimrc
    
  • Absolute:

    ln -sf ~/repositories/config-files/.vimrc ~/.vimrc 
    
  • Automatically converted to the correct relative path (recommended if you have a recent coreutils package):

    ln -rsf ~/repositories/config-files/.vimrc ~/.vimrc