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
Screen.Recording.2025-10-05.at.16.58.38.mov
partial-diff-demo.mov
Using lazy.nvim
{
"ryutaro-asada/partial-diff.nvim",
},
require('partial-diff').setup({
-- Debug options
debug = false,
-- 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
}
}
})
For better character-level diff highlighting, install the VSCode diff algorithm:
- Ensure Node.js is installed on your system
- Run
:PartialDiffInstallVSCode
in 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.
This project is licensed under the MIT License.