Example commands when using vimdiff, in order to compare files, or merge them. Note that on Linux, vimdiff might be the default tool when running into a merge conflict, so it can be handy to know a few commands here.
And remember, you can use your usual vim commands.



CTRL+ww       - navigate between windows
:qa           - quit all windows at once
:only         - quit all windows but the once you're in
:cq           - quit (when all goes terribly wrong!)
]c            - next difference
[c            - previous difference
:bnext        - open previously closed windows
:bprev        - open previously closed windows


zo            - open folded text
zc            - close folded text
zR            - unfold all lines
zM            - fold all lines
:diffupdate   - re-scan the files for differences


do            - diff obtain - cannot be used with range or >2 windows
:diffget 2    - diff get (obtain), from 2nd window
:2,4diffget   - diff get (obtain), certain range
                if line does not exist in your buffer, place below to obtain
dp            - diff put - cannot be used with range or >2 windows
:diffput 3    - diff put, use 3rd buffer
:diffput RE   - diff put, use the buffer which matches "RE" (e.g., "file.c.RE")

If things go terribly wrong

:cq            - abort and exit Vim with an error code
:u             - undo the latest change in the current window

For example when merging in Mercurial: Quit Vim via :cq. It won’t save, and it will return an error code, so Mercurial will not consider the file merged yet, and you can try again via hg resolve filename (hg resolve -l to see list of files, in case you get really confused).

Further Reading

* RTFM: vimdiff
* Use vimdiff as git mergetool
* vim / vimdiff cheatsheet
* Mercurial: Merging with Vim