Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

Vim new file recovery in home

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.

Luckily, 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:

  1. Use vim -r to identify the file you need to recover

  2. Go to ~/.cache/vim/swap and find the swap file - it should be named something like %home%user%.swp

  3. 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: %home%user%att.md.swp

  4. Return to ~ and run recovery again with the newly specified file name: vim -r att.md

  5. You should see the recovery warning and be able to recover your file contents - just save them this time

Hope this helps!

More from Darryl Mitchell
All posts