neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

recover.txt (8197B)


      1 *recover.txt*   Nvim
      2 
      3 
      4 	  VIM REFERENCE MANUAL	  by Bram Moolenaar
      5 
      6 
      7 Recovery after a crash					*crash-recovery*
      8 
      9 You have spent several hours typing in that text that has to be finished
     10 next morning, and then disaster strikes: Your computer crashes.
     11 
     12 		DON'T PANIC!
     13 
     14 You can recover most of your changes from the files that Vim uses to store
     15 the contents of the file.  Mostly you can recover your work with one command:
     16 vim -r filename
     17 
     18                                      Type |gO| to see the table of contents.
     19 
     20 ==============================================================================
     21 1. The swap file					*swap-file*
     22 
     23 Vim stores the things you changed in a swap file.  Using the original file
     24 you started from plus the swap file you can mostly recover your work.
     25 
     26 You can see the name of the current swap file being used with the command:
     27 
     28 :sw[apname]					*:sw* *:swapname*
     29 
     30 Or you can use the |swapname()| function, which also allows for seeing the
     31 swap file name of other buffers.
     32 
     33 The name of the swap file is normally the same as the file you are editing,
     34 with the extension ".swp".
     35 - On Unix, a '.' is prepended to swap file names in the same directory as the
     36  edited file.  This avoids that the swap file shows up in a directory
     37  listing.
     38 - If this file already exists (e.g., when you are recovering from a crash) a
     39  warning is given and another extension is used, ".swo", ".swn", etc.
     40 - An existing file will never be overwritten.
     41 - The swap file is deleted as soon as Vim stops editing the file.
     42 
     43 						*E326*
     44 Technical: If the ".swp" file name already exists, the last character is
     45    decremented until there is no file with that name or ".saa" is
     46    reached.  In the last case, no swap file is created.
     47 
     48 By setting the 'directory' option you can place the swap file in another place
     49 than where the edited file is.
     50 Advantages:
     51 - You will not pollute the directories with ".swp" files.
     52 - When the 'directory' is on another partition, reduce the risk of damaging
     53  the file system where the file is (in a crash).
     54 Disadvantages:
     55 - You can get name collisions from files with the same name but in different
     56  directories (although Vim tries to avoid that by comparing the path name).
     57  This will result in bogus ATTENTION warning messages.
     58 - When you use your home directory, and somebody else tries to edit the same
     59  file, that user will not see your swap file and will not get the ATTENTION
     60  warning message.
     61 
     62 If you want to put swap files in a fixed place, put a command resembling the
     63 following ones in your vimrc:
     64 :set dir=~/tmp		(for Unix)
     65 :set dir=c:\\tmp	(for Win32)
     66 This is also very handy when editing files on floppy.  Of course you will have
     67 to create that "tmp" directory for this to work!
     68 
     69 For read-only files, a swap file is not used right away. The swap file is
     70 created only when making changes.
     71 
     72 The 'swapfile' option can be reset to avoid creating a swapfile.  And the
     73 |:noswapfile| modifier can be used to not create a swapfile for a new buffer.
     74 
     75 :nos[wapfile]   {command}			*:nos* *:noswapfile*
     76 	Execute {command}.  If it contains a command that loads a new
     77 	buffer, it will be loaded without creating a swapfile and the
     78 	'swapfile' option will be reset.  If a buffer already had a
     79 	swapfile it is not removed and 'swapfile' is not reset.
     80 
     81 
     82 Detecting an existing swap file ~
     83 
     84 You can find this in the user manual, section |11.3|.
     85 
     86 								*W325*
     87 The default |SwapExists| handler (|default-autocmds|) skips the |E325| prompt
     88 (and automatically chooses "(E)dit") if the swapfile owner process is still
     89 running and owned by the current user.  This presumes that you normally don't
     90 want to be bothered with the |ATTENTION| message just because you happen to
     91 edit the same file from multiple Nvim instances.  In the worst case (a system
     92 crash) there will be more than one swapfile for the file; use |:recover| to
     93 inspect all of its swapfiles.
     94 
     95 
     96 Updating the swapfile ~
     97 
     98 The swap file is updated after typing 200 characters or when you have not
     99 typed anything for four seconds.  This only happens if the buffer was
    100 changed, not when you only moved around.  The reason why it is not kept up to
    101 date all the time is that this would slow down normal work too much.  You can
    102 change the 200 character count with the 'updatecount' option.  You can set
    103 the time with the 'updatetime' option.  The time is given in milliseconds.
    104 After writing to the swap file Vim syncs the file to disk.
    105 
    106 If the writing to the swap file is not wanted, it can be switched off by
    107 setting the 'updatecount' option to 0.  The same is done when starting Vim
    108 with the "-n" option.  Writing can be switched back on by setting the
    109 'updatecount' option to non-zero.  Swap files will be created for all buffers
    110 when doing this.  But when setting 'updatecount' to zero, the existing swap
    111 files will not be removed, it will only affect files that will be opened
    112 after this.
    113 
    114 If you want to make sure that your changes are in the swap file use this
    115 command:
    116 
    117 				*:pre* *:preserve* *E313* *E314*
    118 :pre[serve]		Write all text for the current buffer into its swap
    119 		file.  The original file is no longer needed for
    120 		recovery.
    121 
    122 A Vim swap file can be recognized by the first six characters: "b0VIM ".
    123 After that comes the version number, e.g., "3.0".
    124 
    125 
    126 Links and symbolic links ~
    127 
    128 On Unix it is possible to have two names for the same file.  This can be done
    129 with hard links and with symbolic links (symlinks).
    130 
    131 For hard links Vim does not know the other name of the file.  Therefore, the
    132 name of the swapfile will be based on the name you used to edit the file.
    133 There is no check for editing the same file by the other name too, because Vim
    134 cannot find the other swapfile (except for searching all of your harddisk,
    135 which would be very slow).
    136 
    137 For symbolic links Vim resolves the links to find the name of the actual file.
    138 The swap file name is based on that name.  Thus it doesn't matter by what name
    139 you edit the file, the swap file name will normally be the same.  However,
    140 there are exceptions:
    141 - When the directory of the actual file is not writable the swapfile is put
    142  elsewhere.
    143 - When the symbolic links somehow create a loop you get an *E773* error
    144  message and the unmodified file name will be used.  You won't be able to
    145  save your file normally.
    146 
    147 ==============================================================================
    148 2. Recovery					*recovery* *E308* *E311*
    149 
    150 Basic file recovery is explained in the user manual: |usr_11.txt|.
    151 
    152 Another way to do recovery is to start Vim and use the ":recover" command.
    153 This is easy when you start Vim to edit a file and you get the "ATTENTION:
    154 Found a swap file ..." message.  In this case the single command ":recover"
    155 will do the work.  You can also give the name of the file or the swap file to
    156 the recover command:
    157 				*:rec* *:recover* *E305* *E306* *E307*
    158 :rec[over] [file]	Try to recover [file] from the swap file.  If [file]
    159 		is not given use the file name for the current
    160 		buffer.  The current contents of the buffer are lost.
    161 		This command fails if the buffer was modified.
    162 
    163 :rec[over]! [file]	Like ":recover", but any changes in the current
    164 		buffer are lost.
    165 
    166 					*E312* *E309* *E310* *E1364*
    167 Vim has some intelligence about what to do if the swap file is corrupt in
    168 some way.  If Vim has doubt about what it found, it will give an error
    169 message and insert lines with "???" in the text.  If you see an error message
    170 while recovering, search in the file for "???" to see what is wrong.  You may
    171 want to cut and paste to get the text you need.
    172 
    173 The most common remark is "???LINES MISSING".  This means that Vim cannot read
    174 the text from the original file.  This can happen if the system crashed and
    175 parts of the original file were not written to disk.
    176 
    177 Be sure that the recovery was successful before overwriting the original
    178 file or deleting the swap file.  It is good practice to write the recovered
    179 file elsewhere and run 'diff' to find out if the changes you want are in the
    180 recovered file.  Or use |:DiffOrig|.
    181 
    182 Once you are sure the recovery is ok delete the swap file.  Otherwise, you
    183 will continue to get warning messages that the ".swp" file already exists.
    184 
    185 
    186 vim:tw=78:ts=8:noet:ft=help:norl: