How linediff.vim compares selected blocks inside Vim
A vim plugin to perform diffs on blocks of code
At a glance
- What is it?
- linediff.vim opens chosen code ranges in editable diff windows. Its two-stage write makes a focused comparison practical once you know which buffer holds each edit.
- Who is it for?
- Use linediff.vim for focused comparisons between selected blocks or conflict variants. Keep whole-file review for changes whose scope extends beyond those ranges, and verify how an excerpt write reaches the parent before using it on an open merge.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 48 days ago.
- What is it written in?
- Mainly Vim Script, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 20, 2026, and from our analysis. They are not legal advice.
Editorial analysis
Two ranges become a diff in one Vim tab
Duplicated code often lives in separate corners of the same file. For example, two branches of a parser may normalize input differently after months of independent edits. Comparing the entire file against itself tells a maintainer little about those branches. linediff.vim lets the maintainer mark each relevant range and compare the selected text in a separate tab. The first selection gets signs at its boundaries. The second selection gets its own signs and opens the two excerpts in vertical diff windows. Choose ranges that begin and end at comparable boundaries. Selecting a surrounding function declaration on only one side adds a difference that may distract from the expression under review. Treat those boundaries as the scope of the comparison and inspect surrounding callers separately before adopting an edit.
Preview a local comparison with three ranges
The project is available from the AndrewRadev/linediff.vim repository and its linked vim.org script page. The README supplies usage commands. Once the plugin is loaded, make a disposable Vim buffer with six lines, arranged as three two-line variants of the same operation. The upstream example uses explicit line numbers to mark three areas.
:1,2Linediff
:3,4LinediffAdd
:5,6LinediffAdd
:LinediffShowThe first command establishes the initial range and the next two accumulate excerpts. The final command opens a comparison of all three. A visual selection also works when the relevant ranges are easier to identify by structure than by line number. The documented eight-diff limit comes from Vim. For a larger census of duplicated blocks, split the work into smaller comparisons with one common reference range, keeping the reference unchanged until the inspection is complete.
A temporary buffer write changes the parent buffer
Each excerpt is editable in its temporary window. Writing that buffer transfers the edited text to the corresponding range in the parent buffer. The parent stays open with the resulting change in memory and has its own write step. This distinction matters when a maintainer edits one of two excerpts to test a refactor and then closes the comparison. Reset removes the temporary buffers and signs while preserving edits already transferred to the parent. The reset command also has a forced form that discards unsaved changes in the temporary buffers. In a trial on disposable text, inspect the original range after each write and again after resetting. That sequence makes it clear which edit has moved into the parent and which file still needs a save.
Conflict buffers allow a maintainer to choose a side
In a merge conflict, the plugin can find the markers around the cursor and show their contents as diff buffers. This handles the two-side format as well as the three-way format with a base. The diff windows identify the merge parents in their statuslines. A maintainer can pick the contents of one diff buffer to replace the full conflict region in the parent. The pick command can also operate directly in a conflict region. Picking is suitable when one version already contains the desired resolution. When separate sides contain compatible changes, read both versions and inspect the combined result in the parent before treating the conflict as resolved. Compare the surrounding code as well, especially when a conflict includes only a few lines of a larger conditional.
Statusline choices affect how editors identify an excerpt
The default statusline describes the original buffer and range. With a custom statusline containing the filename token, the plugin substitutes that description for the token. Without that token, it sets a statusline of its own. Users who depend on their existing statusline can turn off this behavior with the documented setting and still retrieve the description through the buffer-local differ object. The buffer-ready user event offers a place for buffer-local setup, such as a quit mapping specific to the diff windows. The repository records a last push on 2026-10-09 and lists v0.3.0 from 2017-04-01. When configuring an editor from the tagged release, confirm which documented commands and hooks that checkout contains. The project's MIT license calls for retaining the applicable notices in redistributed copies.
Whole-file comparisons have a different review scope
A whole-file diff is a useful alternative when the question is how two files or revisions differ from beginning to end. That view keeps adjacent edits visible. A range comparison is more direct for two functions embedded in an otherwise unrelated body of code, especially when the editor needs to apply a result directly to a selected block. Copying both snippets into scratch files can also isolate them for a comparison, but the editor then has to transfer any chosen changes back to the original location manually. In a patch review where the set of affected files is itself part of the evidence, keep the repository diff open and use linediff.vim for a focused question inside that review. A small excerpt can hide surrounding changes on which its correctness depends.
Editorial conclusion
Use linediff.vim for focused comparisons between selected blocks or conflict variants. Keep whole-file review for changes whose scope extends beyond those ranges, and verify how an excerpt write reaches the parent before using it on an open merge.
Frequently asked questions
Can linediff.vim compare three ranges?
Yes. Mark the first range, add two further ranges and open the diff. Vim limits the comparison to eight areas.
Does writing a linediff.vim window save the original file?
Writing a temporary diff buffer updates the parent buffer. Save the parent separately to write the file.
Can linediff.vim resolve a three-way conflict?
It can display all three variants and use the selected diff buffer to replace the conflict region.
Official sources
Was this useful?