SkillAgentSearch skills...

Diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.

Install / Use

/learn @sindrets/Diffview.nvim
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.

preview

Introduction

Vim's diff mode is pretty good, but there is no convenient way to quickly bring up all modified files in a diffsplit. This plugin aims to provide a simple, unified, single tabpage interface that lets you easily review all changed files for any git rev.

Requirements

  • Git ≥ 2.31.0 (for Git support)
  • Mercurial ≥ 5.4.0 (for Mercurial support)
  • Neovim ≥ 0.7.0 (with LuaJIT)
  • nvim-web-devicons (optional) For file icons

Installation

Install the plugin with your package manager of choice.

" Plug
Plug 'sindrets/diffview.nvim'
-- Packer
use "sindrets/diffview.nvim" 

Merge Tool

merge tool showcase

Opening a diff view during a merge or a rebase will list the conflicted files in their own section. When opening a conflicted file, it will open in a 3-way diff allowing you to resolve the merge conflicts with the context of the target branch's version, as well as the version from the branch which is being merged.

The 3-way diff is only the default layout for merge conflicts. There are multiple variations on this layout, a 4-way diff layout, and a single window layout available.

In addition to the normal :h copy-diffs mappings, there are default mappings provided for jumping between conflict markers, obtaining a hunk directly from any of the diff buffers, and accepting any one, all, or none of the versions of a file given by a conflict region.

For more information on the merge tool, mappings, layouts and how to configure them, see:

  • :h diffview-merge-tool
  • :h diffview-config-view.x.layout

File History

file history showcase

The file history view allows you to list all the commits that affected a given set of paths, and view the changes made in a diff split. This is a porcelain interface for git-log, and supports a good number of its options. Things like:

  • Filtering commits by grepping commit messages and commit authors.
  • Tracing the line evolution of a given set of line ranges for multiple files.
  • Only listing changes for a specific commit range, branch, or tag.
  • Following file changes through renames.

Get started by opening file history for:

  • The current branch: :DiffviewFileHistory
  • The current file: :DiffviewFileHistory %

For more info, see :h :DiffviewFileHistory.

Usage

:DiffviewOpen [git rev] [options] [ -- {paths...}]

Calling :DiffviewOpen with no args opens a new Diffview that compares against the current index. You can also provide any valid git rev to view only changes for that rev.

Examples:

  • :DiffviewOpen
  • :DiffviewOpen HEAD~2
  • :DiffviewOpen HEAD~4..HEAD~2
  • :DiffviewOpen d4a7b0d
  • :DiffviewOpen d4a7b0d^!
  • :DiffviewOpen d4a7b0d..519b30e
  • :DiffviewOpen origin/main...HEAD

You can also provide additional paths to narrow down what files are shown:

  • :DiffviewOpen HEAD~2 -- lua/diffview plugin

For information about additional [options], visit the documentation.

Additional commands for convenience:

  • :DiffviewClose: Close the current diffview. You can also use :tabclose.
  • :DiffviewToggleFiles: Toggle the file panel.
  • :DiffviewFocusFiles: Bring focus to the file panel.
  • :DiffviewRefresh: Update stats and entries in the file list of the current Diffview.

With a Diffview open and the default key bindings, you can cycle through changed files with <tab> and <s-tab> (see configuration to change the key bindings).

Staging

You can stage individual hunks by editing any buffer that represents the index (after running :DiffviewOpen with no [git-rev] the entries under "Changes" will have the index buffer on the left side, and the entries under "Staged changes" will have it on the right side). Once you write to an index buffer the index will be updated.

:[range]DiffviewFileHistory [paths] [options]

Opens a new file history view that lists all commits that affected the given paths. This is a porcelain interface for git-log. Both [paths] and [options] may be specified in any order, even interchangeably.

If no [paths] are given, defaults to the top-level of the working tree. The top-level will be inferred from the current buffer when possible, otherwise the cwd is used. Multiple [paths] may be provided and git pathspec is supported.

If [range] is given, the file history view will trace the line evolution of the given range in the current file (for more info, see the -L flag in the docs).

Examples:

  • :DiffviewFileHistory
  • :DiffviewFileHistory %
  • :DiffviewFileHistory path/to/some/file.txt
  • :DiffviewFileHistory path/to/some/directory
  • :DiffviewFileHistory include/this and/this :!but/not/this
  • :DiffviewFileHistory --range=origin..HEAD
  • :DiffviewFileHistory --range=feat/example-branch
  • :'<,'>DiffviewFileHistory

[!IMPORTANT]

Familiarize Yourself With :h diff-mode

This plugin assumes you're familiar with all the features already provided by nvim's builtin diff-mode. These features include:

  • Jumping between hunks (:h jumpto-diffs).
  • Applying the changes of a diff hunk from any of the diffed buffers (:h copy-diffs).
  • And more...

Read the help page for more info.


<br>

[!NOTE] Additionally check out USAGE for examples of some more specific use-cases.

<br>

Configuration

<p> <details> <summary style='cursor: pointer'><b>Example config with default values</b></summary>
-- Lua
local actions = require("diffview.actions")

require("diffview").setup({
  diff_binaries = false,    -- Show diffs for binaries
  enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
  git_cmd = { "git" },      -- The git executable followed by default args.
  hg_cmd = { "hg" },        -- The hg executable followed by default args.
  use_icons = true,         -- Requires nvim-web-devicons
  show_help_hints = true,   -- Show hints for how to open the help panel
  watch_index = true,       -- Update views and index buffers when the git index changes.
  icons = {                 -- Only applies when use_icons is true.
    folder_closed = "",
    folder_open = "",
  },
  signs = {
    fold_closed = "",
    fold_open = "",
    done = "✓",
  },
  view = {
    -- Configure the layout and behavior of different types of views.
    -- Available layouts:
    --  'diff1_plain'
    --    |'diff2_horizontal'
    --    |'diff2_vertical'
    --    |'diff3_horizontal'
    --    |'diff3_vertical'
    --    |'diff3_mixed'
    --    |'diff4_mixed'
    -- For more info, see |diffview-config-view.x.layout|.
    default = {
      -- Config for changed files, and staged files in diff views.
      layout = "diff2_horizontal",
      disable_diagnostics = false,  -- Temporarily disable diagnostics for diff buffers while in the view.
      winbar_info = false,          -- See |diffview-config-view.x.winbar_info|
    },
    merge_tool = {
      -- Config for conflicted files in diff views during a merge or rebase.
      layout = "diff3_horizontal",
      disable_diagnostics = true,   -- Temporarily disable diagnostics for diff buffers while in the view.
      winbar_info = true,           -- See |diffview-config-view.x.winbar_info|
    },
    file_history = {
      -- Config for changed files in file history views.
      layout = "diff2_horizontal",
      disable_diagnostics = false,  -- Temporarily disable diagnostics for diff buffers while in the view.
      winbar_info = false,          -- See |diffview-config-view.x.winbar_info|
    },
  },
  file_panel = {
    listing_style = "tree",             -- One of 'list' or 'tree'
    tree_options = {                    -- Only applies when listing_style is 'tree'
      flatten_dirs = true,              -- Flatten dirs that only contain one single dir
      folder_statuses = "only_folded",  -- One of 'never', 'only_folded' or 'always'.
    },
    win_config = {                      -- See |diffview-config-win_config|
      position = "left",
      width = 35,
      win_opts = {},
    },
  },
  file_history_panel = {
    log_options = {   -- See |diffview-config-log_options|
      git = {
        single_file = {
          diff_merges = "combined",
        },
        multi_file = {
          diff_merges = "first-parent",
        },
      },
      hg = {
        single_file = {},
        multi_file = {},
      },
    },
    win_config = {    -- See |diffview-config-win_config|
      position = "bottom",
      height = 16,
      win_opts = {},
    },
  },
  commit_log_panel = {
    win_config = {},  -- See |diffview-config-win_config|
  },
  default_args = {    -- Default args prepended to the arg-list for the listed commands
    DiffviewOpen = {},
    DiffviewFileHistory = {},
  },
  hooks = {},         -- See |diffview-config-hooks|
  keymaps = {
    disable_defaults = false, -- Disable the default keymaps
    view = {
      -- The `view` bindings are active in the diff buffers, only when the current
      -- tabpage is a Diffview.
      { "n", "<tab>",       actions.select_next_entry,              { desc = "Open the diff for the next file" } },
      { "n", "<s-tab>",     actions.select_prev_entry,              { desc = "Open the diff for the previous file" } },
      { "n", "[F",          actions.select_first_entry,             { desc = "Open the diff for the first file" } },
      { "n", "]F",          actions.select_last_entry,              { desc = "Open the diff for the last file" } },
      { 
View on GitHub
GitHub Stars5.5k
CategoryDevelopment
Updated3h ago
Forks175

Languages

Lua

Security Score

85/100

Audited on Mar 29, 2026

No findings