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!
Written by Dwain Faithfull
Related protips
3 Responses
Why not: git mergetool
You can also define vim as mergetool, like here -> https://github.com/bartekd/dotfiles/blob/master/.gitconfig#L53
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.