111

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. ...


36

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 ...


16

Backup files 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 ...


16

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 of the commands are inside of vim recover the file r save the recovered file (if the destination file exists, then overwrite) :sav! ~/.recovered open the ...


12

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 ...


11

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.


10

I made a plugin vim-autosave which uses Vim 8 feature of Timers to periodically save your buffers.


5

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. if isdirectory($...


4

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 Explained: " start diff in current window with restored swap file :diffthis " read origin file in new vsplit :vnew | ...


3

:ls shows the current buffers (opened files) A + mark before file path shows that file is modified. Check :h :ls for more details


3

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 ...


3

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: if exists(':keeppatterns') let s:keeppatterns = 'keeppatterns ' else let s:keeppatterns = '' endif augroup AutoSaveGroup ...


2

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 type &...


2

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 set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp


2

Since you do not need the swap-functionality, you can disable it using :set noswapfile or include set noswapfile in your .vimrc.


1

Adding to what muru posted, here's a 'not easy' way to control the processes hanging out there: create and chmod +x type.py: #!/usr/bin/python import argparse import fcntl,termios p = argparse.ArgumentParses() p.add_argument('fname') p.add_argument('test') args = p.parse_args() fd = open(args.fname,'w') for c in args.text: fcntl.ioctl(fd,termios....


1

Put this on your vimrc: """"""""""""""""""""""""""""""""""""""""""""""""""""""""&...


1

Try to saves the buffer whenever text is changed: autocmd TextChanged,TextChangedI <buffer> silent write This works for me. Source


1

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).


1

This is what I do in my vimrc: fun! MkdirIfNeeded(dir, flags, permissions) if !isdirectory(a:dir) call mkdir(a:dir, a:flags, a:permissions) endif endfun " Set (& create if needed) a temp directory to keep backup & swap files if has('win32') let whoami = substitute(system("whoami /LOGONID"), '\n', '', '') let tmpdir = 'C:/tmp/...


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