gvim — E303: Unable to open swap file for “[No Name]“, recovery impossible
vim is my editor of choice and I install it in Windows. All is working quite good except one little annoyance — when I open the editor fresh and started editing by going into insert mode, it will give this error message:
1 | E303: Unable to open swap file for "[No Name]", recovery impossible |
This is usually harmless, as soon as I save the file everything would be great, it’s just that 1 – 2 seconds of pause that doesn’t make me feel good, so today I tried to pin down the problem and here’s how it went:
1 2 3 4 5 6 7 | :help E303 (So it's related to the swap file. Let's see where our swap file fails to be created.) :set directory? directory=.;c:\tmp;c:\temp (Oh, those are the default %TEMP% which I moved to another drive! But anyway, the first priority should be the current directory. So let's see where we're now) :pwd C:\Windows\system32 |
Solution
OK it’s pretty obvious now. It probably needs a little bit of manual fixing. Let’s put this in our .vimrc
1 2 3 4 5 | " Thanks for an anonymous guest to provide this generic, better solution set directory=.,$TEMP " This is line I used at first. The above line is better than this set directory=.,d:\temp |
Great, problem solved!
just a remark, it should be set directory=.,whatever
not ;
Comment by Juan on December 10, 2009 at 6:40 pm
@Juan: Thanks! Fixed.
Comment by kizzx2 on December 10, 2009 at 6:44 pm
Or more generically:
set directory=.,$TEMP ” default dir for swap files
Comment by guest on January 21, 2010 at 2:04 am
Awesome! Thanks – that did the trick.
Comment by Charles Strahan on February 17, 2010 at 8:27 am
Thanks. Worked wonderfully.
Comment by Josimar on February 21, 2010 at 9:26 am
Brilliant! This was making me angry (at least it was making me use VIM less). Thanks!
Comment by Timothy Chen Allen on June 27, 2010 at 10:33 am
I’ve been too lazy to google for a fix for about 6 months now :S All it took was about 30 seconds thanks to your post. Seeing as to how this bug was causing me to wait around 10 seconds at least every time I opened a new Vim window, I could have saved around 10-20 minutes of my life if I’d only visited earlier
Mucho gracias!
Comment by Indian on September 25, 2011 at 1:33 pm
Thank you so much! I use vim for little scratch files all the time and it was annoying to have my first edit command cut off with that error.
Comment by Jason on October 23, 2011 at 12:52 am
Like others, your post was helped me eliminate a nagging but minor issue. Thank you!
Comment by William Ward on November 14, 2011 at 10:45 pm
Thanks for the fix, this has been pestering me since I installed windows 7.
Probably needs to be added into the next gvim installer also, would probably save alot of people world wide some time.
Comment by Joshua on November 25, 2011 at 9:02 am
Thanks.
Comment by KevinO on December 6, 2011 at 9:58 am