sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.93k stars 107 forks source link

[feature] Add `jumpto-diffs` and `copy-diffs` mappings? #386

Open briandipalma opened 1 year ago

briandipalma commented 1 year ago

I'd like to improve the experience of using diffview to craft a change/commit.

When in the DiffviewOpen Diffview could we navigate around the selected file without having to move focus to it. It would be nice if [c and ]c worked from the file panel, on the local version. I know all this is doing is saving a few keystrokes around moving focus but it would be nice if it was builtin. Along with that a default keybindings for diffget to revert a change would be nice, I'd suggest X but it is already used so maybe x instead?

briandipalma commented 1 year ago

And when a hunk is reverted jump to the next hunk? Maybe a binding to stage the focused hunk? I think it's a nicer workflow than using gitsigns or lazygit to quickly craft/filter changes into staging.

sindrets commented 1 year ago

It would be nice if [c and ]c worked from the file panel [...] Along with that a default keybindings for diffget

You can set this up in your own config using :h diffview-actions-view_windo:

local actions = require("diffview.actions")
require("diffview").setup({
  keymaps = {
    file_panel = {
      {
        "n", "[c",
        actions.view_windo(function(layout_name, sym)
          if sym == "b" then
            vim.cmd("norm! [c")
          end
        end)
      },
      {
        "n", "]c",
        actions.view_windo(function(layout_name, sym)
          if sym == "b" then
            vim.cmd("norm! ]c")
          end
        end)
      },
      {
        "n", "x",
        actions.view_windo(function(layout_name, sym)
          if sym == "b" then
            vim.cmd("diffget")
          end
        end)
      },
    }
  },
})

But I suppose those would be good default mappings.

gegoune commented 1 year ago

This works very nicely and I would definitely welcome it as a default. What would be even better is if it could cross file boundaries as well, as in, jump to next diff in next file if on last diff of a file already. And [C & ]C to jump to first/last diff of current file as well maybe?

briandipalma commented 1 year ago

Yes, crossing file boundaries would be awesome and [C/]C makes sense too.