recover.txt 7.5 KB

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