diffview.nvim icon indicating copy to clipboard operation
diffview.nvim copied to clipboard

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

Open briandipalma opened this issue 2 years ago • 4 comments

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 avatar Jun 27 '23 11:06 briandipalma

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.

briandipalma avatar Jun 27 '23 11:06 briandipalma

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.

sindrets avatar Jun 30 '23 09:06 sindrets

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?

gegoune avatar Jul 06 '23 08:07 gegoune

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

briandipalma avatar Jul 06 '23 09:07 briandipalma