I normally use git on the command line.
But when there is a merge conflict I use Vim to resolve them with (personally I do it with with the fugitive plugin). Note: fugitive is good for a lot of git manipulation from within Vim. My favorite feature is the 3 way diff of a merge conflict.
git supports this in vimdiff via git mergetool. I have installed ...
Here is another alternative:
First copy the lines which are 4 lines below to the after the current line (:h :t) then delete the consecutive b lines (:h :d)
Even better is this command:
Which means, for each line starting with a find the next line starting with 'b' and move it to below the current line.
There is no dedicated way to do that (as far as I know), but yeah, it can be done with a few commands:
function! Interleave(start, end, where)
if a:start < a:where
for i in range(0, a:end - a:start)
execute a:start . 'm' . (a:where + i)
for i in range(a:end - a:start, 0, -1)
I used the trick from this SO question to see what the command line was, and got this:
:exe '!tr "\0" " " </proc/' . getpid() . '/cmdline'
:!tr "\0" " " </proc/23932/cmdline
gvim -f -d -c wincmd J foo ./foo_LOCAL_23800 ./foo_BASE_23800 ./foo_REMOTE_23800
So the trick is using Ctrl-WJ (via :wincmd):
Not exactly what you asked, but may find this useful: Splice plugin: a Vim plugin for resolving conflicts during three-way merge.
It has a nice demo screencast on Vimeo.
If you are going to stick with the default vimdiff you could create a function to retrieve the buffer number for the surronding windows and use them to call :diffget twice:
yank and put can work without any plugins or extra functions, though it is, perhaps, a bit less convenient than do or dp
Just copy the needed bits from the parent buffers and paste them into the correct spot in the merged buffer. This is also useful if you want just part of a diff block, rather than the whole thing.
You may, at times, need to force Vim to ...
To combine changes from both the target and merge branches in a single command:
You can just delete the lines with Git conflict markers. The following two methods will delete all lines that start with:
Method 1: Manually Entering and Executing a Command
If you want to have a little bit of fun with macros and marks you could try something like this:
First put a mark (here a) on the line containing a1 with ma
Go to the line containing b1 and mark it with mb
Start recording a macro in the register you want (here the register q) with qq
Insert the folowing in your macro: ddmb'apjma'b
Stop recording the macro ...
To elaborate on the Christian Brabandt's comment, here is a decomposition of the DiffOrig command:
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
command DiffOrig " create a new command named DiffOrig
vert new " open a new buffer splitted vertically
| set bt=...
For completeness I use the following git config for mergetool. It uses the vim-fugitive plugin:
conflictstyle = merge
tool = fugitive
cmd = vim "+Gdiff" $MERGED
I also dabbled with my own version that handled the three way merge with mutliple tabs for different perspectives. However, I found that the above fugitive ...
It seems that at some point, running the diffupdate command solves the problem.
:diffupdate updates the current diff view. It changes the diff colors to match the new state between files. It also update the folds, that are displayed to keep the diff buffer relatively small.