Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 33273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:53:42+00:00 2026-05-10T13:53:42+00:00

When a previous Vim session crashed, you are greeted with the Swap file …

  • 0

When a previous Vim session crashed, you are greeted with the ‘Swap file … already exists!’ for each and every file that was open in the previous session.

Can you make this Vim recovery prompt smarter? (Without switching off recovery!) Specifically, I’m thinking of:

  • If the swapped version does not contain unsaved changes and the editing process is no longer running, can you make Vim automatically delete the swap file?
  • Can you automate the suggested process of saving the recovered file under a new name, merging it with file on disk and then deleting the old swap file, so that minimal interaction is required? Especially when the swap version and the disk version are the same, everything should be automatic.

I discovered the SwapExists autocommand but I don’t know if it can help with these tasks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:53:42+00:00Added an answer on May 10, 2026 at 1:53 pm

    I have vim store my swap files in a single local directory, by having this in my .vimrc:

    set directory=~/.vim/swap,. 

    Among other benefits, this makes the swap files easy to find all at once. Now when my laptop loses power or whatever and I start back up with a bunch of swap files laying around, I just run my cleanswap script:

    TMPDIR=$(mktemp -d) || exit 1 RECTXT='$TMPDIR/vim.recovery.$USER.txt' RECFN='$TMPDIR/vim.recovery.$USER.fn' trap 'rm -f '$RECTXT' '$RECFN'; rmdir '$TMPDIR'' 0 1 2 3 15 for q in ~/.vim/swap/.*sw? ~/.vim/swap/*; do   [[ -f $q ]] || continue   rm -f '$RECTXT' '$RECFN'   vim -X -r '$q' \       -c 'w! $RECTXT' \       -c 'let fn=expand('%')' \       -c 'new $RECFN' \       -c 'exec setline( 1, fn )' \       -c w\! \       -c 'qa'   if [[ ! -f $RECFN ]]; then     echo 'nothing to recover from $q'     rm -f '$q'     continue   fi   CRNT='$(cat $RECFN)'   if diff --strip-trailing-cr --brief '$CRNT' '$RECTXT'; then       echo 'removing redundant $q'       echo '  for $CRNT'       rm -f '$q'   else       echo $q contains changes       vim -n -d '$CRNT' '$RECTXT'       rm -i '$q' || exit   fi done 

    This will remove any swap files that are up-to-date with the real files. Any that don’t match are brought up in a vimdiff window so I can merge in my unsaved changes.

    –Chouser

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 105k
  • Answers 106k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Wanted to clear up a bit of confusion here. Extension… May 11, 2026 at 8:49 pm
  • Editorial Team
    Editorial Team added an answer If you use xalan its possible to use an xpath… May 11, 2026 at 8:49 pm
  • Editorial Team
    Editorial Team added an answer Here's a link to the docs for mpmovieplayercontroller: http://developer.apple.com/iphone/library/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/occ/instm/MPMoviePlayerController/initWithContentURL: It's… May 11, 2026 at 8:49 pm

Related Questions

When a previous Vim session crashed, you are greeted with the Swap file ...
I have recently started using Vim as my text editor and am currently working
According to the documentation, a prepared query provides a significant performance benefit if you're
The VXML application I mentioned in a previous question is now in testing. After
I'm trying to bring myself up to speed on C#, having never developed for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.