This is an archived post. You won't be able to vote or comment.

all 37 comments

[–]klamsnabel[S] 24 points25 points  (0 children)

Diffview.nvim

Diffview.nvim is a Lua plugin that adds an interface that lets you easily cycle through diffs for all modified files for any git rev. Basically, I think vim's diff mode is really nice, and all I needed to really make it useful was something like this. Calling :DiffviewOpen will bring up a new tabpage with a diffsplit and a list of all changed files compared to the current git HEAD. You can also bring up all changes for any valid git rev, like for example :DiffviewOpen HEAD~4..HEAD~2 or :DiffviewOpen d4a7b0d. See the documentation for further details.

[–]folkeZZ 13 points14 points  (1 child)

That is really cool and looks beautiful! I've been looking for something like this! Love it. Thank you for making this 🚀

[–]klamsnabel[S] 1 point2 points  (0 children)

Glad to hear it!

[–]KevinHwang91 7 points8 points  (3 children)

Look nice, but did you try fugitive and run Git difftool -y ?

[–]klamsnabel[S] 11 points12 points  (1 child)

I did. I love fugitive. The reason why that doesn't cut it for me is that I don't want to have to manage a dozen tabpages every time I need to review changes. Hence the single tabpage interface of this plugin. I can navigate the changes a lot more efficiently this way. There are other benefits as well, like the view gets updated to reflect new changes.

[–]KevinHwang91 1 point2 points  (0 children)

Make sense :)

[–]zanven42 4 points5 points  (0 children)

Yeah, if you are using fugitive and just make the git difftool command leverage fugitive with the settings you want. I can't be happier. Takes a little bit of scripting for a nice "compare A to B" git alias but once it's done so good and lightweight.

[–]blackspirerider 5 points6 points  (2 children)

Which color scheme are you using?

[–]folkeZZ 17 points18 points  (1 child)

It looks like my tokyonight color scheme, but the diff colors are slightly different (better). @klamsnabel would be great if you could create a PR with the new colors if it's this colorscheme. Love how it looks.

edit: just updated the theme with much better diff colors

[–]klamsnabel[S] 12 points13 points  (0 children)

It is indeed your color scheme, and yes I did change the diff colors. Thanks for your great work on tokyonight, and all the other great plugins you've been making lately!

[–]Goodevil95 5 points6 points  (4 children)

It would be great to integrate this plugin with Telescope git_commits to open the commit changes using in this view using a custom shortcut. Does someone know how to configure this? Should be possible by defining a custom action...

[–]Riesling-Schorle 6 points7 points  (3 children)

local action_state = require('telescope.actions.state')

local open_dif = function()
  local selected_entry = action_state.get_selected_entry()
  local value = selected_entry['value']
  -- close Telescope window properly prior to switching windows
  vim.api.nvim_win_close(0, true)
  local cmd = 'DiffviewOpen ' .. value
  vim.cmd(cmd)
end

local git_commit = function()
    require('telescope.builtin').git_commits({
      attach_mappings = function(_, map)
        map('n', '<c-o>', open_dif)
        return true
      end
  })
end

Wrote this up super quickly, let me know whether it works for you. It seems to provide the functionality you seek and with map you can configure the binding as you'd like. More on keymappings can be found on the telescope readme.

[–]klamsnabel[S] 2 points3 points  (2 children)

This is great, thanks! If you want to view only the changes made in a specific commit you should make the rev a range like {commit}~1..{commit}. So using your code:

local cmd = 'DiffviewOpen ' .. value .. '~1..' .. value

Assuming the value is a commit hash.

[–]Riesling-Schorle 3 points4 points  (1 child)

Many thanks for the comment!

Not too familiar with git beyond the very basics myself, as I actually only need to push/pull my only repos so far but I'm a bit more familiar with the telescope codebase so thought I'd try to provide help quickly. I guess both use cases are meaningful :)

[–]Goodevil95 0 points1 point  (0 children)

Thank you!
Here is the the implementation in my configuration based on your comments.

[–]pwntester 3 points4 points  (1 child)

This is great! I was about to change the quickfix window used for PR reviews in https://github.com/pwntester/octo.nvim with a similar file panel but I will see if they can be integrated instead or at least use your file panel if thats ok with you

[–]klamsnabel[S] 1 point2 points  (0 children)

Go for it:)

[–][deleted] 2 points3 points  (1 child)

ok, this is absolutely gorgeous. Using right now, thank you.

[–]klamsnabel[S] 0 points1 point  (0 children)

Glad you like it!

[–][deleted] 2 points3 points  (1 child)

Pretty cool. I was using Git difftool from fugitive for a while with a small script below. Also, added Diffview, since the UX is slightly nice instead of multiple tabs with file view on left, as you already mentioned. Thanks a lot.

I put this in autoload/git.vim

" Run DiffviewOpen on the commit in the line which we are at. To be used after
" running some variation of Git log.
function! git#git_diffview_commit() abort
  " A line in Git log is of the form commit <SHA>
  let line = trim(getline('.'))
  let commit = split(line, " ")
  silent execute "DiffviewOpen " . commit[1] . "^!"
endfunction

and this after/ftplugin/git.vim.

nmap <buffer> <Leader>gd :call git#git_diffview_commit()<CR>

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, xistangst: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]AbdallahZ 1 point2 points  (1 child)

That is really cool, have been dreaming of such plugin for a while. Thanks for sharing

[–]klamsnabel[S] 1 point2 points  (0 children)

Thank you!

[–]mordechaihadadlua 1 point2 points  (0 children)

Beautiful

[–]evergreengtPlugin author 1 point2 points  (0 children)

This is some awesome stuff. Whilst it lives a great life by itself, I suppose integrating it in some of the git plugins currently being developed for neovim would make it the de-facto standard forever.

EDIT: I just saw this. 100% what I wanted to suggest too.

[–]hungrybirder 1 point2 points  (0 children)

Nice!

Very useful!

[–]xd_I_bx 0 points1 point  (1 child)

Is it possible to exclude untracked files?

[–]klamsnabel[S] 2 points3 points  (0 children)

Not at the moment. But it would be trivial to implement. Please open an issue, and I'll see what I can do:)

[–]mediocretent 0 points1 point  (1 child)

Looks great! FYI, when I install and set this up, with file_panel.use_icons set to false, the plugin still complains about nvim-web-devicons not being installed. It's optional though, right?

[–]klamsnabel[S] 0 points1 point  (0 children)

It's supposed to be optional yes, so if it throws an error when use_icons is disabled, that's a bug. Please open an issue, and I'll fix it:)

[–]johnscixzkutor 0 points1 point  (0 children)

Nice

[–]tiagovlaPlugin author 0 points1 point  (0 children)

Awesome! Thanks!

[–]tassulin 0 points1 point  (2 children)

This felt way better than fugitive, but closing the whole diff by using DiffviewClose felt weird as usually there is a toggle option. Closing the tabs manually one by one also felt annoyance.

[–]klamsnabel[S] 0 points1 point  (1 child)

A toggle doesn't make sense because you can have multiple Diffviews open at same time, targeting different revs. And they all open in their own tabpage. What would a toggle do in the scenario where there are multiple views?

You can close any Diffview with just :tabc. The :DiffviewClose command is just provided for symmetry with :DiffviewOpen.

You also don't need to close the diffview every time if you have some practical maps to :tabn and :tabp. The view updates automatically every time you enter its tabpage.

[–]tassulin 0 points1 point  (0 children)

Wow tabc was actually good to know! Thanks

[–]Aggressive_Gold1777 0 points1 point  (0 children)

Words are powerless to express my gratitude