Skip to content

Instantly share code, notes, and snippets.

@gagbo
Created November 22, 2017 14:18
Show Gist options
  • Save gagbo/4650cd713974792cc8edc6e5bcd00ecb to your computer and use it in GitHub Desktop.
Save gagbo/4650cd713974792cc8edc6e5bcd00ecb to your computer and use it in GitHub Desktop.
Properly manage swap files in vim
augroup SwapfileManagement " From a tpope snippet.
autocmd!
" The trick is that resetting 'swapfile' deletes the swapfile.
" The if is most likely for the cases when dir is nuked while editing
autocmd CursorHold,BufWritePost,BufReadPost,BufLeave *
\ if isdirectory(expand("<amatch>:h")) |
\ let &swapfile = &modified | endif
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment