Usefull vimdiff commands to view diff and merge

October 15, 2008 @ 8:20 am · Filed under Linux

Diffing the files and merging them is one of the very common task we do everyday. Following are few very useful commands to view the diff using vim and merge them using the vimdiff commands instead of copying and pasting from one file to another.

To diff two files using vim :

vimdiff file1 file2
vim -d file1 file2

Ofcourse you can use gvim also but I don’t prefer using GVIM.

gvimdiff file1 file2

Commands :

[c : Jump to previous diff
]c : Jump to the next diff

do or :diffget : Diff obtain (get the changes to the current buffer/file from the other buffer)
dp or :diffput : Diff Put (Put the changes from the current buffer/file to the other buffer)

As this being one of very command task I do, I have mapped them to single keys for the easy access.

nmap <F7> [czz
nmap <F8> ]czz
nmap <F2> do
nmap <F3> dp

The zz in the end of the command [c will center at the point of the diff so that we can view the diff clearly.

~Enjoy Vim