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 instances of Vim from editing the same file. This can be useful on multi-user systems or just to know if you have another Vim already editing a file.
There isn't a builtin option, although :help 'autosave' (in todo.txt) refers to a description of what such an option could do.
One possible way to implement this is to use the CursorHold autocommand event. This event is triggered when the user hasn't pressed a key for 'updatetime' milliseconds.
autocmd CursorHold * update
The :update command only saves ...
By default, Vim doesn't leave backup files behind. They are merely transient files that exist while Vim is saving the buffer to disk. As described in :help backup-table this behavior can be controlled by the 'backup' and 'writebackup' options:
'backup' 'writebackup' action ~
off off no backup made
off on backup ...
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
all the rest of the commands are inside of vim
recover the file
save the recovered file (if the destination file exists, then overwrite)
open the ...
Vim does have an auto-save feature, but it saves it to the "recovery" file.
When you edit a document, e.g. MyFile.txt vim will create the revovery file .MyFile.txt.swp. If your system were to crash, or your session were to die, then you can reconnect, and recover from essentially where you left off, by typing:
vim -r MyFile.txt
This will open the file for ...
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 you edit the same file). The result may or may not have your latest edits, but it's better than nothing. Do check that everything is ok.
I use my .vimrc on multiple machines, including shared servers. I don't necessarily want people being able to see the files that I'm working on and I like keeping my home directory relatively clean. So this is my solution which will work on Linux and Mac OS X just fine.
" Sets central temp file location, to prevent local default behavior.
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 "norm! ggdd" | :diffthis
" start diff in current window with restored swap file
" read origin file in new vsplit
:vnew | ...
If you can modify those files, it's likely that Vim created swap files for them. Swap files have extensions .swp, .swo, ..., etc. You can search for these files using find. Looking in your home directory, for example:
find ~ -type f -name '.*.sw?'
If the Vim programs are still running, you could expedite the search by looking at which files are opened by ...
I make my Vim save everything every time focus is lost.
autocmd FocusLost <your-patterns-here> silent! wall
My patterns are pretty long and I use them in several autocmds but for completeness this is what it looks like:
let s:keeppatterns = 'keeppatterns '
let s:keeppatterns = ''
Based off Trevor's answer, I made the following commands for dealing with swap files:
noremap <LEADER>s <C-w>o:sav! ~/.vim/.recovered<CR>:vs<CR><C-w>w:bn<CR>
noremap <LEADER>t :wa<CR>:bp\|bd #<CR><C-o>
Upon reaching the ATTENTION: Found a swap file... prompt, I
type r to recover the swap
As others have indicated, vim has a swap file (.swp) that will be created where ever your original file is, but in your .vimrc file, you can set the .swp directory.
You'll need to create the directory with mkdir and then set your .vimrc to that location.
set backup " make backup files
Adding to what muru posted, here's a 'not easy' way to control the processes hanging out there:
create and chmod +x type.py:
p = argparse.ArgumentParses()
args = p.parse_args()
fd = open(args.fname,'w')
for c in args.text:
The vim-workspace plugin has a fairly customizable auto-save feature that may suit your needs. By default, it enables autosave when in a workspace session (its main feature), but you can set it to always autosave if that's all you're looking for (let g:workspace_autosave_always = 1).
This is what I do in my vimrc:
fun! MkdirIfNeeded(dir, flags, permissions)
call mkdir(a:dir, a:flags, a:permissions)
" Set (& create if needed) a temp directory to keep backup & swap files
let whoami = substitute(system("whoami /LOGONID"), '\n', '', '')
let tmpdir = 'C:/tmp/...