I'm trying to diff two files using gvimdiff file1 file2. This works in certain parts of my file system, but if I'm several directories deep, it stops working. Instead, it'll open three files and one of the diffed files will be in a nonexistent nested duplicate directory---you'll see what I mean below.

For example, say I want to open a file in the directory c:\a\b\c\d\e\.

  1. I navigate to that directory containing file1 and file2.
  2. Just to check, dir shows the contents of the directory and file1 and file2 are both present as expected.
  3. I run the command gvimdiff file1 file2.
  4. Three files are opened, shown below.
1. c:\a\b\c\d\e\file1 (correct file in diff mode)
2. c:\a\b\c\d\e\c\d\e\file2 (non existent, blank, correctly named in diff mode)
         |_____|_____|--- Notice the duplicated part of the filepath!
3. c:\a\b\c\d\e\file2 (correct file, not in diff mode, not current buffer)

If I try the exact same procedure, but I'm in c:\users\my_name\, then everything works as expected. For now, I've gotten things to work by using

gvimdiff file1 ..\..\..\file2

and if I go one folder deeper or shallower, I have to add or remove a ..\ to compensate.

What is going on here and how might I fix it?

  • 1
    This is an interesting problem, but unfortunately it isn't fully clear to me what you mean. Can you give perhaps an example with steps that demonstrate how you reproduce this problem? For example, cd \a\b\c\d\e then dir then gvimdiff file1 file2 and file2 is not found but with the series of ..`s it works, etc. Can you also see what :pwd` is inside Vim and what :file reports for each file? Please edit the question with the additional information. – filbranden Aug 29 at 15:21
  • 1
    Thanks. I'll update the post for clarity. I solved the issue though and I'll post the solution below. – JDG Aug 29 at 15:24
  • 1
    Awesome, thanks for that!!! – filbranden Aug 29 at 15:25

I remembered that I can load vim without any vimrc file using this command, which made the problem disappear.

gvimdiff -u NONE file1 file2

I went to my vimrc and commented out the first 30 lines, then the first 60 lines, and so on until the problem disappeared. The offending line in my vimrc was cd c:\a\b. (I'm using dummy names for the file system of course.) Changing this line to autocmd VimEnter * cd c:\a\b fixed the problem. Thanks @filbranden for the suggestion!

| improve this answer | |
  • 2
    I think you can use a VimEnter event to change directory after Vim has opened the files: autocmd VimEnter * cd c:\a\b, but not sure this will always work when passing multiple arguments and wildcards to Vim... Anyways, consider trying it if it interests you. Feel free to update your answer if it does do what you want. – filbranden Aug 29 at 17:11
  • 1
    That works perfectly. Thank you for the elegant solution. I'll update my answer. – JDG Aug 29 at 19:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.