Code for Concinnity

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:

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:

:help E303
(So it's related to the swap file. Let's see where our swap file fails to be created.)
:set directory?
(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)


OK it’s pretty obvious now. It probably needs a little bit of manual fixing. Let’s put this in our .vimrc

" 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!

Published by kizzx2, on November 6th, 2009 at 3:58 am. Filled under: Useful tips Tags: , , , 18 Comments

18 Responses to “gvim — E303: Unable to open swap file for “[No Name]”, recovery impossible”

  1. just a remark, it should be set directory=.,whatever

    not ;

    Comment by Juan on December 10, 2009 at 6:40 pm

  2. @Juan: Thanks! Fixed.

    Comment by kizzx2 on December 10, 2009 at 6:44 pm

  3. Or more generically:

    set directory=.,$TEMP ” default dir for swap files

    Comment by guest on January 21, 2010 at 2:04 am

  4. Awesome! Thanks – that did the trick.

    Comment by Charles Strahan on February 17, 2010 at 8:27 am

  5. Thanks. Worked wonderfully.

    Comment by Josimar on February 21, 2010 at 9:26 am

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. Thanks.

    Comment by KevinO on December 6, 2011 at 9:58 am

  12. I had the same problem once while creating LVM partitions. Then I have executed the below command from the recovery mode itself and it worked..

    mount -n -o remount /

    Then I could edit the file. For your better LUCK!!

    Comment by Amit Saha on August 11, 2012 at 2:31 am

  13. Thanks..

    Comment by Peter on November 6, 2012 at 12:48 pm

  14. +1! Thank you!

    Comment by Michael on May 4, 2013 at 1:14 am

  15. Very helpful: thanks!

    Comment by Phil on June 27, 2013 at 2:16 am

  16. I’m on Windows 8 so I found it easier to make a directory symlink to $TEMP on c:\tmp and c:\temp. This will help with other *nix ports that want to use those folders too. (“mklink /D c:\tmp %TEMP%” in cmd as admin) Gosh, I love symlinks so much, when I heard Vista introduced them back then it was the sole reason for me to switch from XP.

    Comment by DAud on September 13, 2013 at 2:47 pm

  17. Thanks a lot!

    Comment by Felix on November 11, 2015 at 4:19 pm

  18. 6 year old post still helping people out! My issue was I hadn’t escaped the backslash in my temp path specified in my .vimrc Thanks!

    Comment by Mark on February 13, 2016 at 8:37 am

Leave a Reply