I have an nvi session that got interrupted, and I'd like to recover my edits.

When I type vi -r, it tells me "no files to recover." But there is a recovery file in /var/tmp/vi.recover, and when I run strings on that file, I can see that it contains text from the interrupted session. So if I can point nvi to that recovery file, I should be able to recover my edits.

However, there appears to be no (documented) way to specify a recovery file. The -r option does not take any parameters of its own; the only thing that can follow it is the name of the original file. But since vi has apparently lost the association between the original file and the recovery file, vi -r myfile just tells me, "No files named myfile, readable by you, to recover". How can I tell it to use a given recovery file? Thanks.

1 Answer 1


It seems that nvi uses a special "index file" in /var/tmp/vi.recover/, named recover.XXXXX (where XXXXX is randomly generated). On my system the contents look like:

X-vi-recover-file: /home/martin/recover
X-vi-recover-path: /var/tmp/vi.recover/vi.AI8Iqs
Reply-To: root
From: root (Nvi recovery program)
To: martin
Subject: Nvi saved the file recover
Precedence: bulk

On Mon Jun 22 17:30:01 2015, the user martin was editing a
file named /home/martin/recover on the machine
martin-xps.lico.nl, when it was saved for recovery. You can
recover most, if not all, of the changes to this file using
the -r option to nvi:

        nvi -r /home/martin/recover

By creating a new /var/tmp/vi.recover/recover.XXXXXX file with the above contents, and changing the first two "headers" (X-vi-recover-file and X-vi-recover-path) to the correct paths, you should be able tell nvi to pick up your recovery file.

... This seems to be the "easiest" way, as far as I can see ...

  • Thanks for the response. I don't believe the recover.XXXXX file is acting as an index; I actually have one of these files in /var/tmp/vi.recover/ (from a different editing session, one whose loss I don't care about) and its presence does not make vi -r display any results. This file appears to just contain the text of the autogenerated email. But I think this is the right track: somewhere nvi must store an index associating original files with recovery files, and adding the appropriate entry to this index would solve my problem.
    – Targeloid
    Commented Jun 22, 2015 at 16:50
  • Odd. Despite vi -r not acknowledging the existing recover.XXXXX file, when I created a new phony one with the file I care about, nvi picked it up and recovered it without complaint. Perfect!
    – Targeloid
    Commented Jun 22, 2015 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.