Vim new file recovery in home
November 11, 2022•267 words
Hyper specific title, right?
I use both Standard Notes and Obsidian for note taking, but still find myself firing up
vim when I need to quickly take a note. In this case I was porting a cell phone number and needed to quickly take down the port PIN and account number. This all sounds fine, but where I went wrong was in forgetting to save.
vim has a file recovery feature. In the event you've actually editing a saved file, this recovery screen will present itself the next time you edit that file - it works well, and has saved me many times. But what about when you're doing what I was and creating a file from scratch in your home directory?
I'm not sure if it's a bug with
vim or not, but for some reason when attempting to recover an unnamed file in
~ (home) the
vim recovery interprets the
.swp file as a directory. I noticed this and found a quick fix:
vim -rto identify the file you need to recover
~/.cache/vim/swapand find the swap file - it should be named something like
Rename this file - in my case I just used a .md extension since that was the final format I wanted, but in general I don't think it matters:
~and run recovery again with the newly specified file name:
vim -r att.md
You should see the recovery warning and be able to recover your file contents - just save them this time
Hope this helps!