Where does VIM (gvim/macvim) keep swap files for unsaved/unnamed buffers?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 Where Does Vim (Gvim/Macvim) Keep Swap Files For Unsaved/Unnamed Buffers?
00:52 Accepted Answer Score 89
02:13 Answer 2 Score 6
02:32 Answer 3 Score 1
03:28 Answer 4 Score 0
04:02 Thank you
--
Full question
https://superuser.com/questions/195894/w...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim #gvim #swap #macvim
#avk47
ACCEPTED ANSWER
Score 89
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
ANSWER 2
Score 6
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 possible with :recover _
.
ANSWER 3
Score 1
The answer is: all over the place. The trick is finding the right one. Some are in your /tmp directory, but lots of them are somewhere under your home directory.
There maybe more efficient ways to do this, but the following worked for me when I lost an unnamed file (on MacBook):
in home directory, search for backup files (takes a few seconds, and can probably be made smarter):
find ./ -name ".s*" > findVimBackups.txt
open file:
vim findVimBackups.txt
remove file names that aren't for backups of unnamed files:
:g!/\/\.s..$/d
:g/svn/d
Now I see a list of the locations of unnamed backup files. In each of those directories I run the following until I find the file(s) from today:
ls -ltra <directory>
I cd into the right directory and open vim and type :recover and select the correct backup.
ANSWER 4
Score 0
It seems that they will end up in your working directory :pwd
This is wherever you opened vim or alternately you might have set it using :cd
or similar.
swap files for unnamed buffers seem to just get dumped in there with no filename so you'll end up with .swp .swn .swo etc. I discovered this not when trying to recover something but when my hg ignore file wasn't covering enough different suffixes!
I guessed having lots of unnamed buffers with changes might have been the cause and deleting these buffers caused the mystery files to disappear