2022 Developer Survey is open! Take survey.
122 votes
Accepted

What is the purpose of swap files?

Reasons for swap files Swap files store changes you've made to the buffer. If Vim or your computer crashes, they allow you to recover those changes. Swap files also provide a way to avoid multiple ...
user avatar
  • 10.3k
38 votes
Accepted

VIM swap-file best practices?

Don't Panic! Recovering files is always safe, because vim never writes any changes until you write them yourself. So recovering from a swap file and then closing without saving won't change anything. ...
user avatar
24 votes

What's the difference between "quit" and "abort"?

Try this: run vim file1 in a terminal, then run vim -p file1 file2 in a different terminal. The second command will prompt you as above. If you answer Quit, you still get to edit file2. If you ...
user avatar
  • 3,568
22 votes

How do you view the diff of a swap file without quitting `vim`?

Here is the vim commands you need to view the diff, resolve any differences, save the file without quitting vim or using plugins: from the command line open the file vim path/to/file all the rest ...
user avatar
14 votes

vim: (E)dit anyway without prompting

Through the SwapExists event, you can influence the choice (and skip the dialog) by setting the special v:swapchoice variable: autocmd SwapExists * let v:swapchoice = "e" (I personally would at ...
user avatar
  • 16.6k
11 votes
Accepted

Can a text file be recovered only from the .*.swp file?

Edit the same file again. Vim will prompt you with a few options; say you want to Recover. Then save the file, quit Vim, and remove the swap file (otherwise Vim will prompt you again the next time ...
user avatar
  • 3,849
11 votes
Accepted

Does Vim autosave?

Yes it saves to swap file. You can do a quick test to get a feel of this. Go to a directory. Say vim notest.txt and write some text. You do not even have to save the file. If you list files in the ...
user avatar
  • 1,207
9 votes
Accepted

How to detect whether swp files contain unsaved changes?

vim -r at the command line will list all swap files in the current directory and temporary directories, and whether they contain any unsaved changes. Look for the line that says modified: no/YES. I ...
user avatar
  • 980
8 votes

How to detect whether swp files contain unsaved changes?

Is it possible to only have .*.swp-files, when file on disk and file in vim are different? Yes. The snippet below (adapted from tpope's vimrc) will disable the swap file for a buffer when it isn'...
user avatar
  • 10.3k
8 votes
Accepted

Force prompt for whether to delete a swap file

The "Delete it" option isn't displayed if the Vim process is still running; I can't find this documented anywhere but I looked it up in the source code; from memline.c, line 4512 (slightly simplified):...
user avatar
7 votes
Accepted

How to resolve E303 (Unable to open swap file) on Linux machine?

Vim does not interpolate the ~ when using the let & syntax. You must do this manually using expand(). se nobackup writebackup let s:vim_cstmztn_files_dir=expand('~/tools/Vim_Files/') let &...
user avatar
  • 12.6k
6 votes
Accepted

edit file without swap file within a vim session

You could try :noswapfile e FILENAME: :nos[wapfile] {command} *:nos* *:noswapfile* Execute {command}. If it contains a command that loads a new buffer, it will be loaded ...
user avatar
  • 6,370
6 votes

How do you view the diff of a swap file without quitting `vim`?

View diff of a swap file without plugins Without plugins, you can use vim alternate-file. Wikia source: Diff current buffer and the original file In short, try this: :diffthis | :vnew | r # | exe &...
user avatar
  • 391
6 votes

VIM swap-file best practices?

Personally, I have turned off swap and backup files, as it tends to create swap files and backup files everywhere and frequently creates conflicts. Vim's persistent-undo has been much more reliable ...
user avatar
  • 825
6 votes
Accepted

How can I view the name of the swapfile being used for the current buffer?

:swapname This will show the filename of the swapfile for the current buffer. (For example: /c/path/.swu) I found this (after a few tries) by typeing :swTAB. I also found this question: VIM swap-...
user avatar
  • 226
5 votes
Accepted

Swap choices: how can I "skip" instead of "quit" or "abort"?

I agree with you, and this seems like it could be improved, because one of those you would think would not create the buffer, and I just verified that I see the same behavior you describe, but if I ...
user avatar
5 votes

Why does `set nocompatible` result in vim saving extra, all-numeric temporary files?

When writing a buffer Vim will create a temporary file which it will fchown() to verify it has permission to create files in this directory; simplified version from buf_write() in src/fileio.c: /* * ...
user avatar
5 votes
Accepted

Disable swap file for large files

You can combine autocommands with the getfsize(file) function to automatically disable options for large files. " A global variable that contains the size of which a file is considered " large. In ...
user avatar
5 votes

What's the difference between "quit" and "abort"?

@FDinoff suggested checking the vim help. In case anyone wanted to see these more easily: WHAT TO DO? *swap-exists-choices* If dialogs are supported you will be ...
user avatar
  • 151
5 votes

How to prevent vim from creating (and leaving) temporary files over webdav?

The options you need are directory and backupdir they allow you to set the directory where swap files and backup files are stored. The second part of the problem is how to detect that you are ...
user avatar
  • 45.9k
5 votes
Accepted

Discover which other user(s) are accessing a file

I think you might be misinterpreting the meaning/operation of the swap file. The swap file might indicate that some other person/process is currently editing that file, but it doesn't necessarily ...
user avatar
  • 27.4k
4 votes

"E297: Write error in swap file" due to running in a VM

I have the same problem with @Jiaming Zhang, no space left on server. So I use df -h to check overall disk usage and use du -sh * to find space of each folder. After I deleted some large directories, ...
user avatar
  • 41
4 votes
Accepted

"E297: Write error in swap file" due to running in a VM

I would try to globally disable swapfiles and then reenable them for all buffers. Something like this: :bufdo :set noswapfile swapfile (One might want to check, whether the current buffer has a ...
user avatar
4 votes
Accepted

What does shortmess+=A do about the swp file?

If you set A option Vim will just forget about swap at all. You'll stop getting messages about a swap file being found and if you're editing the same file in different terminals at the same time, it'...
user avatar
  • 156
4 votes

Raise window holding swap file

One solution would be to use a single instance of vim per project, which would prevent this issue unless your multiple projects had overlapping files. I'm going to assume that you are looking for a ...
user avatar
  • 191
3 votes

Raise window holding swap file

Long lost and almost forgotten. Meant to re-factor the code etc. but post is as is. This code is used on a 32-bit system. Not sure how it would behave on 64-bit (or other). Have a hack in C-code ...
user avatar
  • 1,207
2 votes

What does shortmess+=A do about the swp file?

According to :help swap-file: If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc. An existing ...
user avatar
2 votes
Accepted

.swp swap files for directories while browsing with netrw

This is probably a netrw bug. You might be able to work around by creating a file ~/.vim/after/ftplugin/netrw.vim (create non-existent directories) and put in there :set noswapfile
user avatar
2 votes

How to allow editing of a file from other sources while it's already open in vim?

I believe the option you're looking for is autoread. To use it put this in your vimrc: set autoread From :h 'autoread': When a file has been detected to have been changed outside of Vim and ...
user avatar
  • 7,406
2 votes

"E297: Write error in swap file" due to running in a VM

You could try using sessions instead of suspending the VM. You could configure your Linux to launch Vim on startup, and your Vim to load the last session. Anyway, for the following task: I am ...
user avatar
  • 6,370

Only top scored, non community-wiki answers of a minimum length are eligible