Last Updated: February 25, 2016
·
2.927K
· dwfait

Open Git conflicts in Vim

When rebasing/merging a lot on an active project, you're going to have a lot of conflicts. This shell function will open all current conflicts inside Vim in different buffers, meaning you can fix the conflict, do a :bd to close the buffer and move on to the next file, saving you tons of time!

function editconflicts() { 
  vim $( git diff --name-only --diff-filter=U | xargs )
}

Expanding on this further - you can set Vim to open the files up with the search pattern set to "<<<<<<<", meaning you can easily cycle through the (possibly multiple) conflicts in each file with a simple press of n:

function editconflicts() { 
  vim +/"<<<<<<<" $( git diff --name-only --diff-filter=U | xargs )
}

There! Now you can handle those dreaded conflicts with ease!

3 Responses
Add your response

Why not: git mergetool

over 1 year ago ·

You can also define vim as mergetool, like here -> https://github.com/bartekd/dotfiles/blob/master/.gitconfig#L53

over 1 year ago ·

You can also use Tim Pope's fugitive plugin. When you run :Gdiff on a conflicted file it automatically splits into 3 windows with the Target branch on the left, the file with conflict markers in the middle, and the Merge branch in the right window.

over 1 year ago ·