home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vim53os2.zip / vim-5.3 / doc / recover.txt < prev    next >
Text File  |  1998-08-30  |  10KB  |  217 lines

  1. *recover.txt*   For Vim version 5.3.  Last modification: 1998 May 18
  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. 1. The swap file    |swap-file|
  19. 2. Recovery        |recovery|
  20.  
  21. ==============================================================================
  22. 1. The swap file                    *swap-file*
  23.  
  24. Vim stores the things you changed in a swap file.  Using the original file
  25. you started from plus the swap file you can mostly recover your work.
  26.  
  27. You can see the name of the current swap file being used with the command:
  28.  
  29.     :sw[apname]                    *:sw* *:swapname*
  30.  
  31. The name of the swap file is normally the same as the file you are editing,
  32. with the extension ".swp".
  33. - On Unix, a '.' is prepended to swap file names in the same directory as the
  34.   edited file.  This avoids that the swap file shows up in a directory
  35.   listing.
  36. - On MS-DOS machines and when the 'shortname' option is on, any '.' in the
  37.   original file name is replaced with '_'.
  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. Technical: The replacement of '.' with '_' is done to avoid problems with
  44.        MS-DOS compatible filesystems (e.g., crossdos, multidos).  If Vim
  45.        is able to detect that the file is on an MS-DOS-like filesystem, a
  46.        flag is set that has the same effect as the 'shortname' option.
  47.        This flag is reset when you start editing another file.
  48.  
  49.        If the ".swp" file name already exists, the last character is
  50.        decremented until there is no file with that name or ".swa" is
  51.        reached.  In the last case, no swap file is created.
  52.  
  53. By setting the 'directory' option you can place the swap file in another place
  54. than where the edited file is.
  55. Advantages:
  56. - You will not pollute the directories with ".swp" files.
  57. - When the 'directory' is on another partition, reduce the risk of damaging
  58.   the file system where the file is (in a crash).
  59. Disadvantages:
  60. - You can get name collisions from files with the same name but in different
  61.   directories (although Vim tries to avoid that by comparing the path name).
  62.   This will result in bogus ATTENTION warning messages.
  63. - When you use your home directory, and somebody else tries to edit the same
  64.   file, he will not see your swap file and will not get the ATTENTION waring
  65.   message.
  66. On the Amiga you can also use a recoverable ram disk, but there is no 100%
  67. guarantee that this works.  Putting swap files in a normal ram disk (like RAM:
  68. on the Amiga) or in a place that is cleared when rebooting (like /tmp on Unix)
  69. makes no sense, you will lose the swap file in a crash.
  70.  
  71. If you want to put swap files in a fixed place, put a command resembling the
  72. following ones in your .vimrc:
  73.     :set dir=dh2:tmp    (for Amiga)
  74.     :set dir=~/tmp        (for Unix)
  75.     :set dir=c:\\tmp    (for MS-DOS and Win32)
  76. This is also very handy when editing files on floppy.  Of course you will have
  77. to create that "tmp" directory for this to work!
  78.  
  79. For read-only files, a swap file is not used.  Unless the file is big, causing
  80. the amount of memory used to be higher than given with 'maxmem' or
  81. 'maxmemtot'.  And when making a change to a read-only file, the swap file is
  82. created anyway.
  83.  
  84.                             *ATTENTION*
  85. When starting to edit a file, Vim checks if a swap file already exists for
  86. that file.  If there is one, you will get a message indicating that something
  87. is wrong:
  88.  
  89.     ATTENTION
  90.     Found a swap file by the name "../doc/help.txt.swp"
  91.              dated: Thu May 16 11:46:31 1996
  92.          file name: ~mool/vim/vim/doc/help.txt
  93.          host name: Kibaale
  94.          user name: mool
  95.         process ID: 211 (still running)
  96.     While opening file "../doc/help.txt"
  97.              dated: Wed May 15 21:38:40 1996
  98.  
  99. You are to take one of two actions:
  100.  
  101. 1. Quit editing this file, because another edit session is active on this
  102.    file.  Continuing to edit will result in two versions of the same file.
  103.    The one that is written last will overwrite the other one, resulting in
  104.    loss of changes.  The text "(still running)" indicates that the process
  105.    editing this file runs on the same computer (Unix only).  When working over
  106.    a network you will not see this message, because the process will be
  107.    running on another computer.
  108. 2. Recover a previously crashed edit session.  See below |recovery|.
  109.  
  110. If you really don't want to see this message, you can add the 'A' flag to the
  111. 'shortmess' option.  But it's very unusual that you need that.
  112.  
  113. Vim cannot always detect that a swap file already exists for a file.  This is
  114. the case when the other edit session puts the swap files in another
  115. directory or when the path name for the file is different when editing it on
  116. different machines.
  117.  
  118. The swap file is updated after typing 200 characters or when you have not
  119. typed anything for four seconds.  This only happens if the buffer was
  120. changed, not when you only moved around.  The reason why it is not kept up to
  121. date all the time is that this would slow down normal work too much.  You can
  122. change the 200 character count with the 'updatecount' option.  You can set
  123. the time with the 'updatetime' option.  The time is given in milliseconds.
  124. After writing to the swap file Vim syncs the file to disk.  This takes some
  125. time, especially on busy Unix systems.  If you don't want this you can set the
  126. 'swapsync' option to an empty string.  The risk of loosing work becomes bigger
  127. though.  On some non-Unix systems (MS-DOS, Amiga) the swap file won't be
  128. written at all.
  129.  
  130. If the writing to the swap file is not wanted, it can be switched off by
  131. setting the 'updatecount' option to 0.  The same is done when starting Vim
  132. with the "-n" option.  Writing can be switched back on by setting the
  133. 'updatecount' option to non-zero.  Swap files will be created for all buffers
  134. when doing this.  But when setting 'updatecount' to zero, the existing swap
  135. files will not be removed, it will only affect files that will be opened
  136. after this.
  137.  
  138. If you want to make sure that your changes are in the swap file use this
  139. command:
  140.  
  141.                             *:pre* *:preserve*
  142. :pre[serve]        Write all text for all buffers into swap file.  The
  143.             original file is no longer needed for recovery.  {Vi:
  144.             emergency exit}
  145.  
  146. A Vim swap file can be recognized by the first six characters: "b0VIM ".
  147. After that comes the version number, e.g., "3.0".
  148.  
  149. ==============================================================================
  150. 2. Recovery                        *recovery*
  151.  
  152. In most cases recovery is quite easy: Start Vim on the same file you were
  153. editing when the crash happened, with the "-r" option added.  Vim will read
  154. the ".swp" file and may read bits and pieces of the original file.
  155.  
  156. Example:
  157. >    vim -r help.txt
  158.  
  159. If you were editing without a file name, give an empty string as argument:
  160. >    vim -r ""
  161.  
  162. If there are several swap files that look they may be the one you want to
  163. use, a list is given of these swap files and you are requested to enter the
  164. number of the one you want to use.  In case you don't know which one to use,
  165. just try them one by one and check the resulting files if they are what you
  166. expected.
  167.  
  168. If you know which swap file needs to be used, you can recover by giving the
  169. swap file name.  Vim will then find out the name of the original file from
  170. the swap file.
  171.  
  172. Example:
  173. >    Vim -r .help.txt.swo
  174.  
  175. This is also handy when the swap file is in another directory than expected.
  176. If this still does not work, see what file names Vim reports and rename the
  177. files accordingly.  Check the 'directory' option to see where Vim may have
  178. put the swap file.
  179.  
  180. Note: Vim tries to find the swap file by searching the directories in the
  181. 'dir' option, looking for files that match "filename.sw?".  If wildcard
  182. expansion doesn't work (e.g., when the 'shell' option is invalid), Vim does a
  183. desparate try to find the file "filename.swp".  If that fails too, you will
  184. have to give the name of the swapfile itself to be able to recover the file.
  185.  
  186. Another way to do recovery is to start Vim and use the ":recover" command.
  187. This is easy when you start Vim to edit a file and you get the "ATTENTION:
  188. Found a swap file ..." message.  In this case the single command ":recover"
  189. will do the work.  You can also give the name of the file or the swap file to
  190. the recover command:
  191.                             *:rec* *:recover*
  192. :rec[over] [file]    Try to recover [file] from the swap file.  If [file]
  193.             is not given use the file name for the current
  194.             buffer.  The current contents of the buffer are lost.
  195.             This command fails if the buffer was modified.
  196.  
  197. :rec[over]! [file]    Like ":recover", but any changes in the current
  198.             buffer are lost.
  199.  
  200. Vim has some intelligence about what to do if the swap file is corrupt in
  201. some way.  If Vim has doubt about what it found, it will give an error
  202. message and insert lines with "???" in the text.  If you see an error message
  203. while recovering, search in the file for "???" to see what is wrong.  You may
  204. want to cut and paste to get the text you need.
  205.  
  206. Be sure that the recovery was successfull before overwriting the original
  207. file or deleting the swap file.  It is good practice to write the recovered
  208. file elsewhere and run 'diff' to find out if the changes you want are in the
  209. recovered file.
  210.  
  211. Once you are sure the recovery is ok delete the swap file.  Otherwise, you
  212. will continue to get warning messages that the ".swp" file already exists.
  213.  
  214. {Vi: recovers in another way and sends mail if there is something to recover}
  215.  
  216.  vim:tw=78:ts=8:sw=8:
  217.