How do I pull a diff change from another window into the current buffer in Vim?
Answer
do
Explanation
The do command (diff obtain) is shorthand for :diffget. In Vim's diff mode, it replaces the hunk under the cursor in the current buffer with the corresponding content from the other diff window. This is the fastest way to accept a change from the opposite side when reviewing diffs or resolving merge conflicts.
How it works
dostands for diff obtain — it fetches the change from the other buffer- It acts on the hunk under the cursor, not the entire file
- The complement is
dp(diff put), which pushes the current buffer's version into the other buffer - In a two-buffer diff, Vim automatically picks the other window. In a three-buffer diff, you must specify:
:diffget 2(by buffer number) or:diffget LOCAL/:diffget REMOTEwhen using merge tools
Example
Open two files for comparison:
:vert diffsplit original.txt
Navigate to a changed hunk with ]c, then press:
do
The hunk in your current buffer is replaced with the version from original.txt.
Tips
]cand[cjump to the next and previous diff hunks respectively- After accepting several changes, run
:diffupdateto refresh the diff highlighting if it becomes stale :diffoff!exits diff mode in all windows at once and restores normal display- When using Git's three-way merge (
git mergetool), the buffers are typically labelled LOCAL (2), BASE (3), and REMOTE (4) — use:diffget 2or:diffget 4to pull from each side