Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes it happens to me that due a mistake modify an unsaved file concurrently (for example by a VCS). Sometimes I don't even notice and keep it editing. When I want to save it, I either have to force the save and lose the concurrent modification, or discard my changes. Neither option is gratifying.

Is there a way how to merge both changes instead?

share|improve this question
up vote 2 down vote accepted

This is not easily possibly. The best I can think of is to always use the :DiffOrig command and merge the changes before writing.

share|improve this answer
I just want to add that :DiffOrig isn't a built-in command, it needs to be added. – Petr Pudlák Sep 8 '13 at 17:34

The :DiffOrig command mentioned in another answer is designed for this, but you have a couple other options:

  1. Save your file with a different name, using :saveas new_name. Then you can diff/merge between the two files without any difficulty or risk of losing data.

  2. Do what :DiffOrig does, but manually. Create a new buffer, and read in the file from disk with the :r command. Diff the two buffers or whatever you want to do to make sure you keep the important changes.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .