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

[feature] Add actions for selecting first / last entry

Open emmanueltouzery opened this issue 2 years ago • 2 comments

Hello, I use diffview in a way that I select the current file when opening, using --selected-file=. This works great for me.

However sometimes I want to use diffview to review all the changes. So, I open the diff view, the current file selected, but I'd like to jump to the first file to go through all the files one by one and be sure I didn't miss any of them. I don't know a way to do that... I know of:

lua require'diffview.config'.actions.select_next_entry()

And the equivalent for the previous entry, but how could I jump to the first entry with a single keyboard shortcut? Thank you!

emmanueltouzery avatar Sep 28 '23 20:09 emmanueltouzery

I found a way to achieve that..

      require('diffview').setup {
        keymaps = {
          view = {
            ["F"] = function() -- jump to first file in the diff
              local view = require'diffview.lib'.get_current_view()
              view:set_file(view.panel.files[1], false, true)
            end,
          },

works great!

EDIT this is better:

      require('diffview').setup {
        keymaps = {
          view = {
            ["F"] = function() -- jump to first file in the diff
              local view = require'diffview.lib'.get_current_view()
                view:set_file(view.panel:ordered_file_list()[1], false, true)
            end,
          },

emmanueltouzery avatar Oct 04 '23 20:10 emmanueltouzery

Cool that found a solution! But I think it would still be valuable to have actions for select_[first|last]_entry, so I'll keep the issue open.

sindrets avatar Oct 05 '23 09:10 sindrets

@sindrets I'll have a go adding this feature.

Thank you for creating a very useful plugin.

yungthai avatar Jun 11 '24 04:06 yungthai