1

I am merging two git branches together. I am using vimdiff to do this, so there are three vim panes shown in my terminal.

This same conflict arises hundreds of times in my merge: vimdiff example

Every time I come across it, I want to do the same thing: keep the top two lines from HEAD (pink) and the bottom line from OTHER (blue).

At the moment I am typing: diffg 3 To accept blue's changes, then going into insert mode and changing the etc's to var's manually.

I feel like there must be a quicker way to keep the top two lines from pink and the third line from blue every time. Is there? This would save me a lot of typing.

Thanks.

whatscool
  • 317
  • 2
  • 18

1 Answers1

4

If the conflict is always the same, perhaps, you can use git rerere (What is git-rerere and how does it work?).

If it is not a conflict occurring over different conflicts (like if the conflict is present many times in the file), you can make a macro:

qq

Search for the conflict:

/<<<<<<<

Delete the line:

dd

Find the middle of the conflict:

/=======

Go in line visual mode:

V

Find the line just before the last blue line you want to keep:

/plan-path

Delete all that:

d

Find the end of the conflict:

/>>>>>>>

Delete it

dd

Finally, stop the macro:

q

Once you made the macro, count the number of occurrences of the conflict:

:%s/<<<<<<<//n

Execute the macro as many times:

42@q

If you have other types of conflicts, you can adapt the macro to your needs.

padawin
  • 4,230
  • 15
  • 19