I have a git repository that contains my vimrc file and a couple of other utilities, called myvimrcgit. I then hard link my vimrc to ~/.vimrc, so that they point to the same inodes. Now, when I go to vim and command edit ~/myvimrcgit/vimrc, the buffer actually loads the ~/.vimrc file. Running :echo expand("%") also yields the filename as ~/.vimrc. This is a problem when I want to use Fugitive to do some git operations while editing my vimrc since Fugitive relies on the filename rather than the current working directory. Calling edit on the original vimrc (edit ~/.vimrc) yields the normal ~/.vimrc file.

Any tips on how to disable this functionality and why does vim always resolve filenames this way?

  • The same scenario with hardlinks done outside of Fugitive context has a different result? – B Layer May 25 at 1:28
  • @BLayer I did the same operation with ~/wow and ~/Documents/wow being linked, and the same thing is happening but now it always resolves to ~/Documents/wow no matter if I open the first or the second file. – SalmonKiller May 25 at 4:07
  • I can't reproduce this on either vim 8.1.998 or nvim 0.3.3. That said, either of those does recognize within the context of a single session. It basically goes by the first name you access it by in a given session. – Ed Grimm May 26 at 6:41
  • I'm not sure this is a good idea, generally speaking, since AFAIK git doesn't even honor hardlinks. – B Layer May 26 at 21:19
  • Like EdGrimm I also see behavior where whatever path I open the hardlinked file with remains in Vim even if I try to open it by a different path to the file (in the same session). But you're not seeing this behavior? Regardless of how you open it always goes by the homedir path? That doesn't sound right. Unless it differs by OS... (I only tried with Cygwin/Win10). – B Layer May 26 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.