When you turn off the VIM editor (such as shutting down the terminal or powering off the computer), a. swp file is created, which is a temporary swap file used to back up the contents of the buffer.
It is important to note that if you do not modify the file and just read the file, the. swp file is not generated.
When you exit unexpectedly, the old swap file is not overwritten, but the new interchange file is regenerated. The original file does not have this modification, the file content is the same as when it was opened.
For example, the first time the interchange file is named ". File.txt.swp"; Once again, an interchange file named ". File.txt.swo" is generated, and the third exchange file is ". File.txt.swn";
When you open the file again with VIM, the above interface will appear first.
You can use
-r
To view all SWP files in the current directory
You can also use
-r filename
To recover the file so that the last time you accidentally quit without a saved modification overwrites the file.
Then use the RM command to delete the swap file.
If you do not want Vim to produce swap files, you can use the following command to disable
:set noswapfile
You can also set the build interchange file using the following command:
:set swapfile
Note that the above settings are only valid for the current file.
Depending on the default settings, the swap file is saved every 4000 milliseconds (4 seconds) or 200 characters. We can modify the frequency of saving the swap file using the following command:
:set updatetime=23000:set updatecount=400
Note that if we set the value of Updatecount to 0, then the swap file will not be saved.
Vim creates a swap file by default in the directory where the current file is located, and we can change the directory that the interchange file produces by using the directory option. For example, use the following command to store the swap file in the/tmp directory:
:setdirectory=/tmp
Note that if we store the swap file in a specified directory, a naming conflict occurs when you edit a file of the same name in a different directory. We can set the directory option to a comma-delimited list of directories and the current directory (.) Set as the first option in the directory list so that the swap file is first stored in the current directory.
Vim is not properly exited from the resulting SWP file