Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where does VIM (gvim/macvim) keep swap files for unsaved/unnamed buffers? (If it does so at all).

Background: Throughout a semi intense seminar I was taking notes in an unnamed/unsaved MacVim buffer when the MacBook ran out of juice and powered down out of nowhere (It did not sleep/hibernate as it usually would).

Question: Would anyone know if there is any chance that the unsaved work may have been saved to a swap (.swp) file or the like, that could be recovered?

System details: In particular this happened using MacVim on a Mac OS X 10.5.8 (But possible recovery hints for other versions are of interest too). I have not restarted MacVim yet in case doing so will initiate a cleanup process.

share|improve this question
1  
Clarification: By unsaved I mean never saved. File was created by pressing Command-T (I think equivalent to :tabe), i.e. a new unnamed buffer is opened in a new tab. (I would usually do ':sav somefilename' at a later stage. – davur Oct 5 '10 at 1:15
    
Doesn't matter. See the additions to my answer. – frabjous Oct 5 '10 at 1:28
up vote 36 down vote accepted

Start up vim and try:

:recover <filename>

If the file never had a name, then simply:

:recover

That's your best bet. For more about swap files and recovery, see:

:help usr_11

About the swap files, typically they're saved in the same directory as the file being edited, but with a . added the beginning to make it hidden and .swp at the end, but it's possible to move them elsewhere by something like:

:set directory=~/vimswap

or similar.

See:

:help swap

For all the details.

A vim swap file is not the same as the edited buffer, however, so be sure to read up there on what can be done for recovery.


EDIT: comments answering the question:

[…] It seems to look in your current working directory, ~/tmp, /var/tmp and /tmp for swap files and in my case I always have a current working directory set and that's where it got saved. – dsclementsen Oct 5 '10 at 1:42

also, be sure to check out the vim -r command line arg. This will print out all the swap files found and where they are. In addtion it will have a lot of extra information such as date/modified/username/etc... *– Neg_EV Oct 5 '10 at 13:49*

share|improve this answer
    
This is not going to help. By unsaved, I mean never saved. Meaning I opened a new buffer with :tabe or (Command+T). So we're talking about an unsaved/unnamed buffer. Is there a default location where this sort of unsaved work is stored? – davur Oct 5 '10 at 1:13
2  
Try :recover with no file name. I just tested that for recovering an unnamed file and it worked. Anyway, even if that particular command doesn't help, reading those help files might. – frabjous Oct 5 '10 at 1:24
1  
It doesn't as far as I can tell. I just tested by killing vim externally while editing a new file. But when I ran recover with no argument, it let me choose even from some older sessions. Anyway, the .swp file for an unnmaed buffer is probably in /tmp, but it would be somewhere else depending on whether you had set directory= <something>. – frabjous Oct 5 '10 at 1:35
2  
also, be sure to check out the vim -r command line arg. This will print out all the swap files found and where they are. In addtion it will have a lot of extra information such as date/modified/username/etc... – Neg_EV Oct 5 '10 at 13:49
1  
I had to use the command :recover! to recover my unsaved file. – user268801 Nov 1 '13 at 19:56

I work on Windows 10 and :recover didn't find a swap file. vim -r listed the swap file from the last edit session (also never saved) named _.swp. Recovering was able with :recover _.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .