How to perform a merge if an unsaved file is modified concurrently?

1

1

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?

Petr Pudlák

Posted 2013-08-19T16:42:28.000

Reputation: 2 197

Answers

2

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

Christian Brabandt

Posted 2013-08-19T16:42:28.000

Reputation: 1 196

I just want to add that :DiffOrig isn't a built-in command, it needs to be added.

– Petr Pudlák – 2013-09-08T17:34:32.770

2

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.

Ben

Posted 2013-08-19T16:42:28.000

Reputation: 2 050