FIND THE CAUSE:
nvim also comes with several commands (and pre-installed extensions) that can do this. If you are trying to figure out the cause of the deletion, check your nvim logs as well.
DATA RECOVERY:
You mentioned a .git directory. Did your directory have a git remote? If so, just clone it to local and problem solved.
If not check for a directory named ".trash-{$USER_ID}" if the original was on a mounted external drive, or .local/share/Trash otherwise. It may be in there (unless rm was used to delete. In that case, unless you are backing up your file system, it is probably gone.)
PROTECTING YOUR SYSTEM AGAINST THIS ISSUE:
This is why you will so often see users on here recommending frequent scheduled backups. I personally use a combination of Timeshift and rsync.
Timeshift can be downloaded via apt. It is primarily for backing up your system files and configuration, and lets you set a recurring backup schedule. You can also run manual backups in cases where you are about to do something risky.
rsync comes with Ubuntu. It is just a basic command-line tool for copying files and directories across a network (although it can do so locally as well.)
Rsync is not primarily intended as a stand-alone backup program, at least not in the way that Timeshift or Weresync are. However, it is simple and effective enough at making backups that many of the more comprehensive solutions use it internally for this purpose.
The downside of rsync is that there is no "set it and forget it" method built in. However, the Ubuntu package managers provide many more backup options, each with its own quirks.
It may be cliche at this point to recommend an aggressive backup strategy, but as you can see, it is cliche for a good reason.