How do I compare two files side by side using diff mode?
Answer
:diffthis in both windows
Explanation
The :diffthis command enables diff mode for the current buffer. Running it in two windows shows their differences highlighted.
How it works
- Open two files in splits:
:vsplit other_file - In the first window:
:diffthis - Switch to the second window:
<C-w>w - In the second window:
:diffthis - Differences are now highlighted
Example
:vsplit file2.txt
:diffthis
<C-w>w
:diffthis
Tips
:diffsplit filenameopens a file and enables diff in one step]cand[cjump between diff hunksdo(diff obtain) pulls changes from the other windowdp(diff put) pushes changes to the other window:diffoffdisables diff mode:diffupdaterefreshes after manual edits