A short recipe for using the vim diff-mode to compare files for their differences.
:h diff
To use the diff-mode of vim, start vim on the file to be compared:
user@host:~$ vimdiff diff_test_1.txt diff_test_2.txt
or
user@host:~$ vim -d diff_test_1.txt diff_test_2.txt
On an already running vim:
user@host:~$ vim diff_test_1.txt
Activate the diff-mode in the current window:
:diffthis
Split the window vertically and open the second file diff_test_2.txt
in the new window:
:vnew diff_test_2.txt
Activate the diff-mode in the new window:
:diffthis
Deactivate the diff-mode in the current window:
:diffoff
Force the diff-mode to update:
:diffupdate
Move forward to the next change:
]C
Move backward to the previous change:
[C
Copy the differences from another buffer to the current buffer:
:diffget
Copy the differences from the current buffer to another buffer:
:diffput
A file is opened in vim already and unsaved changes have been made.
Activate the diff-mode in the current window containing the edited file:
:diffthis
Split the window vertically:
:vnew
Load the last saved content of the file in the new window:
:0r#
Delete the last empty line:
:$d
Activate the diff-mode in the new window:
:diffthis
All of the above steps in one single command:
:diffthis | vnew | 0r# | $d | diffthis