1

I lost my whole project which I had written in one file (only 1 day of work).

There are two ways I could've lost it:

  1. I saved the file but accidentally deleted this or used the cp command with wrong arguments (because there is a copy of a similar project in my current file which I used as a starting template).

  2. I didn't save the file all this time and quit; now I just have the template I began with. I am not sure about this one because I remember saving it.

Does Vim keep some kind of in-RAM repository of files which you quit? This would save me a lot of time.

3
  • 3
    You might have undofiles, swapfiles, or backups laying around from Vim, but I have not successfully recovered deleted files from undofiles. The latter two, possibly. Commented Sep 20, 2022 at 20:00
  • I have set backupdir=~/.cache/vim/backup for exactly this reason; which has saved me on a few occasions. I don't know what the default for this is on Neovim, but you can see if it's set (:set backupdir?) and see if your files are in there. Commented Sep 20, 2022 at 21:20
  • Somewhat related btw: vi.stackexchange.com/q/38602/51 Commented Sep 20, 2022 at 21:28

2 Answers 2

1

If you have accidently deleted the file then it's completely gone. Because if you delete a file vim/nvim, it also deletes swap files related to it. So there is no way to recover that file in case it has been deleted. If the file was not deleted manually and the file data was lost due to crashing or any other issue then there is chance that it has a swap file.

To you recover from a swap file you have to do this vim -r FileName If the swap file is there then your file will be successfully recovered and show this message.

 Using swap file ".help.txt.swp" Original file "~/vim/runtime/doc/help.txt" Recovery completed. You should check if everything is OK. (You might want to write out this file under another name and run diff with the original file to check for changes) You may want to delete the .swp file now. 

And if there is no swap file then you get a message like this ~

No swap file found for FileName

If you haven't set up backup then it's likely that there won't be any backup file either. This is why you set up a backup directory as @Martin Tournoij suggested.

0

Encountered this problem myself... Although there is (most of the time) no way to retrieve a deleted file, I ensured with this that it doesn't happen in the future: function to override default delete behavior.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.