diff --git a/nvim/lua/config/plugins.lua b/nvim/lua/config/plugins.lua index 8e359b4..4c2e6cc 100644 --- a/nvim/lua/config/plugins.lua +++ b/nvim/lua/config/plugins.lua @@ -162,9 +162,20 @@ return { 'nvim-tree/nvim-web-devicons', }, config = function() - n 'gd' ':DiffviewOpen' 'Git: Diff' - n 'gc' ':DiffviewClose' 'Git: Close' - n 'gh' ':DiffviewFileHistory' 'Git: History' + local lib = require 'diffview.lib' + + local function toggle(name) + return function() + if not next(lib.views) then + vim.cmd(name) + else + vim.cmd 'DiffviewClose' + end + end + end + + n 'gd' (toggle 'DiffviewOpen') 'Git: Diff' + n 'gh' (toggle 'DiffviewFileHistory') 'Git: History' end },