A Neovim plugin for performing partial diffs on selected code regions with advanced character-level diff highlighting powered by VSCode's diff algorithm.
- π― Partial Diff: Compare any two selected regions of code
- π€ Character-level highlighting: Powered by VSCode's diff algorithm
- π Move detection (optional): Recognize moved code blocks instead of showing them as unrelated changes
- π§Ή Whitespace-aware (optional): Ignore pure indentation / trailing-space changes
- π Histogram fallback: Cleaner built-in diff when the VSCode algorithm is unavailable
Screen.Recording.2025-10-05.at.16.58.38.mov
partial-diff-demo.mov
Using lazy.nvim
{
"ryutaro-asada/partial-diff.nvim",
},Using packer.nvim
use {
'ryutaro-asada/partial-diff.nvim',
config = function()
require('partial-diff').setup()
end
}require('partial-diff').setup({
-- Debug options
debug = false,
-- Diff computation options
diff = {
-- Ignore leading/trailing whitespace differences (vscode-diff).
-- Set to true to hide pure indentation / trailing-space changes.
ignore_trim_whitespace = false,
-- Detect moved code blocks (vscode-diff). When enabled, moved blocks are
-- highlighted with the `line_move` group and marked with virtual text
-- pointing to their counterpart location, instead of being shown as a
-- change.
compute_moves = false,
-- Align corresponding lines between From and To by inserting filler
-- rows (like diff mode), so both windows scroll in lockstep. The number
-- column shows original line numbers (blank on filler rows).
align = true,
-- Keep the From/To windows scroll- and cursor-synced (like diff mode).
-- Applies to the vscode-diff path; the built-in diff fallback already
-- syncs scrolling on its own.
sync_scroll = true,
-- When sync_scroll is on, also turn off 'wrap' in both windows so that
-- horizontal scrolling actually happens (and stays mirrored). Set to
-- false to keep wrap at the cost of no horizontal sync.
sync_scroll_nowrap = true,
-- diffopt used for the built-in Neovim diff fallback (when Node.js /
-- vscode-diff are unavailable). Defaults to the histogram algorithm with
-- linematch for cleaner results on refactored code.
fallback_diffopt =
"internal,filler,closeoff,hiddenoff,algorithm:histogram,linematch:60,context:3,indent-heuristic",
},
-- Highlight customization
highlights = {
-- Link to existing highlight groups
line_change = 'DiffChange',
line_add = 'DiffAdd',
line_delete = 'DiffDelete',
-- Specify custom colors
char_add = {
bg = '#2d5a2d', -- Background color
fg = '#a9dc76', -- Foreground color
bold = true, -- Bold
italic = false, -- Italic
underline = false -- Underline
},
char_delete = {
bg = '#5a2d2d',
fg = '#ff6188',
},
char_change = {
bg = '#4a4a0e',
fg = '#ffd866',
bold = true
},
-- Highlight for moved blocks (used when diff.compute_moves = true)
line_move = {
bg = '#2d3a5a',
fg = '#78a9ff',
},
-- Highlight for filler rows inserted by diff.align (links to DiffDelete
-- by default, like diff mode)
filler = 'DiffDelete',
}
})For better character-level diff highlighting, install the VSCode diff algorithm:
- Ensure Node.js is installed on your system
- Run
:PartialDiffInstallVSCodein Neovim - This will install the required npm packages in the plugin directory
Without this, the plugin will fall back to Neovim's built-in diff.
:PartialDiffFrom- Mark a range of lines as the source (what you're diffing from):PartialDiffTo- Mark a range of lines as the target (what you're diffing to) and display the diff:PartialDiffDelete- Close the current diff view:PartialDiffInstallVSCode- Install VSCode diff algorithm dependencies
:PartialDiffA- Alias for:PartialDiffFrom:PartialDiffB- Alias for:PartialDiffTo
:PartialDiffShowLog- Show the debug log file:PartialDiffClearLog- Clear the debug log file
- Select the first range of lines in visual mode
- Execute
:PartialDiffFrom(or use your keymap) - Select the second range of lines in visual mode
- Execute
:PartialDiffTo(or use your keymap) - View the diff in a new tab with side-by-side comparison
" Select lines 10-20 in visual mode
:'<,'>PartialDiffFrom
" Select lines 30-40 in visual mode
:'<,'>PartialDiffTo
" Close the diff when done
:PartialDiffDelete- vscode-diff - Advanced character-level diff computation
- Neovim 0.10.0 or later
- (Optional) Node.js for VSCode diff algorithm
If you have any suggestions or improvements, feel free to open an issue or submit a pull request.
The test suite lives in spec/ and runs in headless Neovim with
plenary.nvim. Node.js and npm are
needed for the vscode-diff tests.
make testmake test fetches a pinned plenary.nvim into .deps/ and installs the npm
dependencies on first run. The manual fixtures in test/ are reused as test
inputs.
This project is licensed under the MIT License.