Home Explore Blog CI



neovim

1st chunk of `runtime/doc/usr_11.txt`
45657cc27b30dc8aed9477df2a58c5f4b05de5e26b7071a10000000100000fa2
*usr_11.txt*	Nvim

		     VIM USER MANUAL - by Bram Moolenaar

			   Recovering from a crash


Did your computer crash?  And you just spent hours editing?  Don't panic!  Vim
stores enough information to be able to restore most of your work.  This
chapter shows you how to get your work back and explains how the swap file is
used.

|11.1|	Basic recovery
|11.2|	Where is the swap file?
|11.3|	Crashed or not?
|11.4|	Further reading

     Next chapter: |usr_12.txt|  Clever tricks
 Previous chapter: |usr_10.txt|  Making big changes
Table of contents: |usr_toc.txt|

==============================================================================
*11.1*	Basic recovery

In most cases recovering a file is quite simple, assuming you know which file
you were editing (and the harddisk is still working).  Start Vim on the file,
with the "-r" argument added: >

	vim -r help.txt

Vim will read the swap file (used to store text you were editing) and may read
bits and pieces of the original file.  If Vim recovered your changes you will
see these messages (with different file names, of course):

	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. ~

To be on the safe side, write this file under another name: >

	:write help.txt.recovered

Compare the file with the original file to check if you ended up with what you
expected.  Diff mode is very useful for this |08.7|.  For example: >

	:write help.txt.recovered
	:edit #
	:diffsp help.txt

Watch out for the original file to contain a more recent version (you saved
the file just before the computer crashed).  And check that no lines are
missing (something went wrong that Vim could not recover).
   If Vim produces warning messages when recovering, read them carefully.
This is rare though.

If the recovery resulted in text that is exactly the same as the file
contents, you will get this message:

	Using swap file ".help.txt.swp" ~
	Original file "~/vim/runtime/doc/help.txt" ~
	Recovery completed. Buffer contents equals file contents. ~
	You may want to delete the .swp file now. ~

This usually happens if you already recovered your changes, or you wrote the
file after making changes.  It is safe to delete the swap file now.

It is normal that the last few changes can not be recovered.  Vim flushes the
changes to disk when you don't type for about four seconds, or after typing
about two hundred characters.  This is set with the 'updatetime' and
'updatecount' options.  Thus when Vim didn't get a chance to save itself when
the system went down, the changes after the last flush will be lost.

If you were editing without a file name, give an empty string as argument: >

	vim -r ""

You must be in the right directory, otherwise Vim can't find the swap file.

==============================================================================
*11.2*	Where is the swap file?

Vim can store the swap file in several places.  To find it, change to the
directory of the file, and use: >

	vim -r

Vim will list the swap files that it can find.  It will also look in other
directories where the swap file for files in the current directory may be
located.  It will not find swap files in any other directories though, it
doesn't search the directory tree.
   The output could look like this:

	Swap files found: ~
	   In current directory: ~
	1.    .main.c.swp ~
		  owned by: mool   dated: Tue May 29 21:00:25 2001 ~
		 file name: ~mool/vim/vim6/src/main.c ~
		  modified: YES ~
		 user name: mool   host name: masaka.moolenaar.net ~
		process ID: 12525 ~
	   In directory ~/tmp: ~
	      -- none -- ~
	   In directory /var/tmp: ~
	      -- none -- ~
	   In directory /tmp: ~
	      -- none -- ~

If there are several swap files that look like they may be the one you want to
use, a list is

Title: Recovering from a Crash in Vim
Summary
This section of the Vim user manual focuses on how to recover your work after a computer crash. It explains the basic recovery process using the "-r" argument, how to identify the location of swap files, and how to deal with situations where multiple swap files exist.