1

I have a file open in Vim inside a Linux virtual machine guest and I then try to open the file on the Windows host, and I do not get that warning that goes "Swap file blah.swp already exists!" (The file is shared to the guest.) I want that warning because that is the only way I can find out I am already editing the file somewhere else, like in this case, in the VM!

It doesn't matter whether I edit the file on Windows first and then use Vim on Linux in the VM, or I edit the file in the Linux VM and then open the file in Vim on Windows: it's the same result, no warning. You could say the behavior is uniform then from Linux to Windows. In both cases Vim creates a .swo file silently, without complaining as it (I believe) should. However, if the file is opened a second time on the VM while being already open on the VM, I do get the warning, and same thing on Windows (for those who want to ask about my Vim settings).

Reading :help recovery does not give anything informative. Version is Vim 7.4 in both cases.

  • So, the Windows system is the VM host? You say, "I have a file open in Vim inside a VM and I then try to open the file on Windows ..." What do you mean, "open the file"? In what sense is the same file accessible to the host and the VM guest simultaneously? – G-Man Mar 22 '15 at 4:29
  • Edited the question. – user62177541 Mar 22 '15 at 19:31
  • @G-Man, VirtualBox provides this shared filesystem feature (as, I think, does KVM/Libvirt) – roaima Mar 22 '15 at 23:24
  • What file sharing method are you using? CIFS, or something specific to the VM implementation? – Mark Plotnick Mar 22 '15 at 23:48
  • @MarkPlotnick, roaima is correct. I am using the VirtualBox feature for sharing files with the guest. See mount -t vboxsf... – user62177541 Mar 24 '15 at 4:01
0

I guess Vim will not recognize the swap file as belonging to the edited file.

The Vim swap file contains the pathname of the edited file. This makes sense, since you can have your swap files in another directory than the edited file. Apparently, Vim checks that the pathname in the found swapfile matches the file to edit. This would not be in your case, as one path is in the Linux VM and the other path is under Windows.

Unfortunately, I could not find a proof of that theory in the Vim manual and I do not have the time right now to verify it in the sources.

  • 1
    Just fired up VirtualBox with a shared filesystem. Cygwin on the Windows side. vi correctly notices I'm editing a file in the current directory regardless of which side starts the edit first. – roaima Mar 22 '15 at 23:23
0

I thought of trying to reboot the system and see if this still happened and sure enough that cured it, so apparently this is a weird temporary phenomenon. I may leave this thread up in case anyone else sees this problem. I first thought of this solution because I thought I remembered doing this same thing on another machine with a similar VM setup and the problem did not occur there. That in fact was true. The same situation on the other machine did show the warning as it should. So upon reboot, the warnings now appear again.

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.