How to use:
1. From terminal –
$vimdiff file1 file2
2. From Vim –
Open vim and use the following commands if you already have windows with other buffers open in the current tab.
:tabe file1 :vert diffsplit file2
:e file1 :vert diffsplit file2
– If you have two or three windows open in your current tab and they display the buffers that you want to diff, you might want to turn on diff mode for each window:
windo set diff
– vimdiff will correctly highlight differences inside a line (whole line pink, differing characters red).
– If you load up two files in splits (:vs or :sp), you can do :diffthis on each window and achieve a diff of files that were already loaded in buffers
– turning off:
:diffoff can be used to turn off the diff mode.
issuing :diffoff! which will turn off diff mode for all windows in the current tab page
do – Get changes from other window into the current window.
dp – Put the changes from current window into the other window.
]c – Jump to the next change.
[c – Jump to the previous change.
Ctrl W + Ctrl W – Switch to the other split window.
Tips on file comparison:
– Sometimes the difference can be a special character – :set list in Vim will show whitespace. End of lines show as ‘$’ and carriage returns usually show as ‘^M’.
– Counting number of characters in a file from bash –
wc -c filename