Skip to main content

This is a new website theme. Help me improve it and give your feedback (opens in a new tab).

vimdiff

Published:

Tags:

Dev Typesetting
This blog post is more than two years old. It is preserved here in the hope that it is useful to someone, but please be aware that links may be broken and that opinions expressed here may not reflect my current views. If this is a technical article, it may no longer reflect current best practice.

Yesterday I was looking at merging review edits in a LaTeX document. I decided that I would use vimdiff, which meant learning the keybindings (again, for maybe the fifth or sixth time).

It’s pretty easy to use vimdiff once you get the hang of it. Open two files like:

vimdiff file1.tex file2.tex

You navigate between the two windows just like any other split in vim: Ctrl-w followed by h or l (to move left or right). Then you can navigate the documents and merge things:

]c :        - next difference
[c :        - previous difference
do          - diff obtain (merge the diff from the other window)
dp          - diff put (merge the diff to the other window)
zo          - open folded text
zc          - close folded text
:diffupdate - re-scan the files for differences

If you’re using a colorscheme that vimdiff looks awful in, the following could help in your .vimrc (this works great for me using Solarized):

highlight DiffAdd    cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText   cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red