vimtricks.wiki Concise Vim tricks, one at a time.

How do I resolve a 3-way merge conflict in vim-fugitive by picking a specific version?

Answer

:diffget //2

Explanation

When resolving Git merge conflicts with vim-fugitive, running :Gvdiffsplit! opens a 3-way split: your current branch (left), the working file with conflict markers (center), and the incoming branch (right). You can resolve each conflict by pulling the version you want directly into the middle buffer using :diffget with a buffer specifier.

How it works

  • :Gvdiffsplit! — opens the 3-way diff with all three versions
  • The center buffer is the conflicted working file — this is where you make changes
  • //2 refers to the ours buffer (your current branch / HEAD)
  • //3 refers to the theirs buffer (the incoming/merge branch)
  • From the center buffer, :diffget //2 pulls the change from your branch
  • From the center buffer, :diffget //3 pulls the change from the incoming branch
  • After resolving, :Gwrite marks the file as resolved and stages it

Example

:Gvdiffsplit!     " open 3-way split for the conflicted file
" Navigate to a conflict region in the center buffer
:diffget //2      " accept your version (ours)
" or
:diffget //3      " accept their version (theirs)
:Gwrite           " save and stage the resolved file

Tips

  • Use ]c / [c to jump between diff hunks across the three panes
  • In the left or right buffer, :diffput pushes a hunk to the center buffer as an alternative workflow
  • The //2 and //3 shorthand uses Vim's filename//bufnr buffer naming — you can also use :ls to see actual buffer numbers and use those directly
  • After resolving all conflicts, run :only to close the side buffers and return to a single window

Next

How do I re-insert the text from my last insert session and immediately return to normal mode?