sindrets / diffview.nvim

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

How jump to first change by default when open a diff? #440

Closed imroc closed 10 months ago

imroc commented 10 months ago

For example, in DiffviewFileHistory, select a commit and press Enter to open a diff file, the cursor do not jump to file panel, I have to move cursor to my file panel, and then gg]c to the first change every time, which is troublesome.

sindrets commented 10 months ago

The plugin already sets the cursor at the top of the file the first time a diff is opened for a given entry. If folds are enabled - as they are by default - then that is the first diff hunk. Did you disable folds?

[...] in DiffviewFileHistory, select a commit and press Enter to open a diff file, the cursor do not jump to file panel, I have to move cursor to my file panel [...]

Remap the action for <cr> to actions.focus_entry() (See :h diffview-actions-focus_entry). This will bring the cursor directly into the diff buffer when you select an entry.

imroc commented 10 months ago

When I use the default config, it also do not focus the diff, cursor still stays in file history panel, not in file content, is my screen recording (I use LazyVim): diffview

imroc commented 10 months ago

I tried to remap <cr> to actions.focus_entry, it works!

imroc commented 10 months ago

Now I use this config and it works perfect:

        hooks = {
          diff_buf_win_enter = function()
            vim.opt_local.foldenable = false
          end,
          diff_buf_read = function()
            vim.api.nvim_input("gg]czz")
          end,
        },
        keymaps = {
          file_history_panel = {
            {
              "n",
              "<cr>",
              actions.focus_entry,
              { desc = "Open and focus the diff for the selected entry." },
            },
            {
              "n",
              "o",
              actions.focus_entry,
              { desc = "Open and focus the diff for the selected entry." },
            },
            {
              "n",
              "l",
              actions.focus_entry,
              { desc = "Open and focus the diff for the selected entry." },
            },
            {
              "n",
              "<2-LeftMouse>",
              actions.focus_entry,
              { desc = "Open and focus the diff for the selected entry." },
            },
          },
        },

This is my screen recording: diffview2

simanga-dev commented 8 months ago

Is the a way to jump to next file, and how do you config that

imroc commented 8 months ago

Is the a way to jump to next file, and how do you config that

Tab

simanga-dev commented 8 months ago

Thank you... @imroc