A Neovim plugin for displaying inline unified diffs directly in your buffer.
You can install unified.nvim using your favorite plugin manager.
{
'axkirillov/unified.nvim',
opts = {
-- your configuration comes here
}
}
use {
'axkirillov/unified.nvim',
config = function()
require('unified').setup({
-- your configuration comes here
})
end
}
You can configure unified.nvim by passing a table to the setup() function. Here are the default settings:
require('unified').setup({
signs = {
add = "│",
delete = "│",
change = "│",
},
highlights = {
add = "DiffAdd",
delete = "DiffDelete",
change = "DiffChange",
},
line_symbols = {
add = "+",
delete = "-",
change = "~",
},
auto_refresh = true, -- Whether to automatically refresh diff when buffer changes
file_tree = {
width = 0.5, -- Width of the file tree window
filename_first = true, -- Show filename before directory path (Snacks backend only)
},
})
:Unified to display the diff against HEAD and open the file tree.:Unified reset.:Unified <commit_ref>, for example :Unified HEAD~1.unified.nvim supports integration with snacks.nvim's git_diff picker as an alternative file browser. This provides a feature-rich experience with built-in diff previews, git status formatting, and staging capabilities.
Installation:
First, install snacks.nvim:
{
'folke/snacks.nvim',
priority = 1000,
lazy = false,
opts = {
-- your snacks config
}
}
Commands:
:Unified -s HEAD " Use Snacks picker, compare against HEAD
:Unified -s HEAD~1 " Use Snacks picker, compare against HEAD~1
:Unified -s origin/main " Use Snacks picker, compare against origin/main
The Snacks picker provides:
<Tab><c-r>When the default file tree is open, you can use the following keymaps:
j/k or <Down>/<Up>: Move the cursor down/up between file nodes.l: Open the file under the cursor in the main window, displaying its diff.q: Close the file tree window.R: Refresh the file tree.?: Show a help dialog.When the file tree opens, the first file is automatically opened in the main window.
The file tree displays the Git status of each file:
M: ModifiedA: AddedD: DeletedR: RenamedC: Copied?: UntrackedTo navigate between hunks, you'll need to set your own keymaps:
vim.keymap.set('n', ']h', function() require('unified.navigation').next_hunk() end)
vim.keymap.set('n', '[h', function() require('unified.navigation').previous_hunk() end)
For programmatic control, you can use the toggle function:
vim.keymap.set('n', '<leader>ud', require('unified').toggle, { desc = 'Toggle unified diff' })
This toggles the diff view on/off, remembering the previous commit reference.
Unified provides a function-only API for hunk actions. Define your own keymaps or commands if desired.
Example keymaps:
local actions = require('unified.hunk_actions')
vim.keymap.set('n', 'gs', actions.stage_hunk, { desc = 'Unified: Stage hunk' })
vim.keymap.set('n', 'gu', actions.unstage_hunk, { desc = 'Unified: Unstage hunk' })
vim.keymap.set('n', 'gr', actions.revert_hunk, { desc = 'Unified: Revert hunk' })
Behavior notes:
:Unified: Shows the diff against HEAD using the default file tree.:Unified <commit_ref>: Shows the diff against the specified commit reference (e.g., a commit hash, branch name, or tag) using the default file tree.:Unified -s <commit_ref>: Shows the diff against the specified commit reference using the Snacks git_diff picker (requires snacks.nvim).:Unified reset: Removes all unified diff highlights and signs from the current buffer and closes the file tree window if it is open.To run all automated tests:
make tests
To run a specific test function:
make test TEST=test_file_name.test_function_name
MIT