sindrets / diffview.nvim

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

Can I change `gf` to act like standard `gf`? #305

Closed briandipalma closed 1 year ago

briandipalma commented 1 year ago

Great plugin, I've been looking for something that plugs the holes in lazygit for a long time.

I'd like to use diffview for my code reviews. So far my workflow is

  1. Checkout worktree/branch
  2. :DiffviewOpen origin/main...HEAD
  3. Inspect diffs
  4. Open up certain files in a normal buffer using gf to rewrite juniors code :rofl:
  5. Once I've opened 3 or 4 realize I have way to many splits open, start to close them

I'd like to cut out 5. I think Neovim's default gf behaviour is an easier workflow. If I raise a PR that makes the required changes (including the help panel description text) would you accept it?

sindrets commented 1 year ago

Before working on a PR, check if :h diffview-actions-goto_file_edit isn't what you're looking for (it sounds like it is).

briandipalma commented 1 year ago

Yes, it looks like it is. It doesn't answer the workflow concerns. I'd argue the two should be swapped around, gf should call goto_file_edit and goto_file should be unmapped. I think opening a split should be the awkward option. Imagine opening nvim in a fresh branch/worktree that you want to review, opening diffview and gfing a file. You end up in your original tab with a split that has the file you want on one side and above it the empty/blank launch page or a greeter like alpha-nvim.

As you go from the diffview tab to your editor tab you have to keep closing splits. It's just more effort for no benefit that I can see. It can also be awkward if you are working on a lower resolution screen like a laptop, splits are the last thing you want as they end up quite small. So I'd still like to change the current behaviour if that's OK?

sindrets commented 1 year ago

The keymaps are configurable. You can change the default behavior of gf in your own config:

local actions = require("diffview.actions")
require("diffview").setup({
  keymaps = {
    view = {
      { "n", "gf", actions.goto_file_edit },
    },
    file_panel = {
      { "n", "gf", actions.goto_file_edit },
    },
  },
})

The reason why goto_file works the way it does is that it's less destructive this way. Less likely to cause unexpected side effects. Although it is now, it didn't always use to be that 'hidden' was enabled by default. Meaning that abandoning a buffer would cause it to unload.

I also personally prefer the way goto_file_edit works, and I might decide to make it the default behavior at some point in the future, seeing as 'hidden' has been enabled by default for a while now. If you would like to open a PR changing the default, I'd accept it.