UPDATE: I've tried both the :set noswapfile swapfile
solution and the :e!
solution and the swapfile one is better because it retains undo history even for large files, in this case meaning over 1.5 MB. For some reason, :e!
does not keep undo history in those cases even though it does keep it in the normal case (say sub-100KB). The swapfile
solution appears to me now to work under any circumstances, which is very impressive.
A bit of a weird question: How can I cleanly get rid of or move past the error message "E297: Write error in swap file"? I am running GVim when this happens and do not want to be forced to close it down and reopen a new GVim because I don't want to lose all my open buffers and ideally I'd like to keep all my undo history in each file too, but even a solution where I lose undo history would be an improvement. I have one limited workaround right now noted at bottom and am looking for something a little better...
Why would I want to ignore such an error? A good question: I am running GVim in a virtual machine and I have it open on a file on the "host" file system rather than the VM's own file system and I "suspend" the VM. After coming back from the suspend, every GVim window open on a host system file will give this message. So the message is evidently due to the disconnection from the host file system that has to occur when the VM is suspended. GVim obviously thinks it still has a valid perhaps file descriptor and such when it doesn't.
So the way the error arises is not anything alarming and I just need or want a way to move past it without having to close GVim and reopen it. For example, many times I might have this GVim open with many buffers and a lot of things going on. I don't want to be forced to shut down the whole GVim session because of this one error, or even to shut down all buffers open on the host system's file system. When the error occurs, it's quite annoying and pops up every few moments.
What I tried so far is doing :e
on the same file, hoping that might be like refreshing from the file system, and that did not get rid of the error.
I have also tried sort of the nuclear option, :bw
to get rid of the buffer where this is occurring and that does work, but as I say ideally I would like to keep the session in the same state as much as possible, so shutting down buffers is not ideal either. Like let's say I have GVim open on 10 files on the host system. If I have to shut down all the buffers, then it's just as bad as having to shut down GVim altogether.
All of this applies to the command line Vim as well, and I'm using version 7.4 on Linux.