diff --git a/nvim/.config/nvim/lua/plugins/diffview.lua b/nvim/.config/nvim/lua/plugins/diffview.lua new file mode 100644 index 0000000..5108cdc --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/diffview.lua @@ -0,0 +1,117 @@ +-- Lua +local actions = require("diffview.actions") + +require("diffview").setup({ + diff_binaries = false, -- Show diffs for binaries + enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl' + use_icons = true, -- Requires nvim-web-devicons + icons = { -- Only applies when use_icons is true. + folder_closed = "", + folder_open = "", + }, + signs = { + fold_closed = "", + fold_open = "", + }, + file_panel = { + listing_style = "tree", -- One of 'list' or 'tree' + tree_options = { -- Only applies when listing_style is 'tree' + flatten_dirs = true, -- Flatten dirs that only contain one single dir + folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'. + }, + win_config = { -- See ':h diffview-config-win_config' + position = "left", + width = 35, + }, + }, + file_history_panel = { + log_options = { + max_count = 256, -- Limit the number of commits + follow = false, -- Follow renames (only for single file) + all = false, -- Include all refs under 'refs/' including HEAD + merges = false, -- List only merge commits + no_merges = false, -- List no merge commits + reverse = false, -- List commits in reverse order + }, + win_config = { -- See ':h diffview-config-win_config' + position = "bottom", + height = 16, + }, + }, + commit_log_panel = { + win_config = {}, -- See ':h diffview-config-win_config' + }, + default_args = { -- Default args prepended to the arg-list for the listed commands + DiffviewOpen = {}, + DiffviewFileHistory = {}, + }, + hooks = {}, -- See ':h diffview-config-hooks' + keymaps = { + disable_defaults = false, -- Disable the default keymaps + view = { + -- The `view` bindings are active in the diff buffers, only when the current + -- tabpage is a Diffview. + [""] = actions.select_next_entry, -- Open the diff for the next file + [""] = actions.select_prev_entry, -- Open the diff for the previous file + ["gf"] = actions.goto_file, -- Open the file in a new split in previous tabpage + [""] = actions.goto_file_split, -- Open the file in a new split + ["gf"] = actions.goto_file_tab, -- Open the file in a new tabpage + ["e"] = actions.focus_files, -- Bring focus to the files panel + ["b"] = actions.toggle_files, -- Toggle the files panel. + }, + file_panel = { + ["j"] = actions.next_entry, -- Bring the cursor to the next file entry + [""] = actions.next_entry, + ["k"] = actions.prev_entry, -- Bring the cursor to the previous file entry. + [""] = actions.prev_entry, + [""] = actions.select_entry, -- Open the diff for the selected entry. + ["o"] = actions.select_entry, + ["<2-LeftMouse>"] = actions.select_entry, + ["-"] = actions.toggle_stage_entry, -- Stage / unstage the selected entry. + ["S"] = actions.stage_all, -- Stage all entries. + ["U"] = actions.unstage_all, -- Unstage all entries. + ["X"] = actions.restore_entry, -- Restore entry to the state on the left side. + ["R"] = actions.refresh_files, -- Update stats and entries in the file list. + ["L"] = actions.open_commit_log, -- Open the commit log panel. + [""] = actions.scroll_view(-0.25), -- Scroll the view up + [""] = actions.scroll_view(0.25), -- Scroll the view down + [""] = actions.select_next_entry, + [""] = actions.select_prev_entry, + ["gf"] = actions.goto_file, + [""] = actions.goto_file_split, + ["gf"] = actions.goto_file_tab, + ["i"] = actions.listing_style, -- Toggle between 'list' and 'tree' views + ["f"] = actions.toggle_flatten_dirs, -- Flatten empty subdirectories in tree listing style. + ["e"] = actions.focus_files, + ["b"] = actions.toggle_files, + }, + file_history_panel = { + ["g!"] = actions.options, -- Open the option panel + [""] = actions.open_in_diffview, -- Open the entry under the cursor in a diffview + ["y"] = actions.copy_hash, -- Copy the commit hash of the entry under the cursor + ["L"] = actions.open_commit_log, + ["zR"] = actions.open_all_folds, + ["zM"] = actions.close_all_folds, + ["j"] = actions.next_entry, + [""] = actions.next_entry, + ["k"] = actions.prev_entry, + [""] = actions.prev_entry, + [""] = actions.select_entry, + ["o"] = actions.select_entry, + ["<2-LeftMouse>"] = actions.select_entry, + [""] = actions.scroll_view(-0.25), + [""] = actions.scroll_view(0.25), + [""] = actions.select_next_entry, + [""] = actions.select_prev_entry, + ["gf"] = actions.goto_file, + [""] = actions.goto_file_split, + ["gf"] = actions.goto_file_tab, + ["e"] = actions.focus_files, + ["b"] = actions.toggle_files, + }, + option_panel = { + [""] = actions.select_entry, + ["q"] = actions.close, + }, + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/init.lua b/nvim/.config/nvim/lua/plugins/init.lua index 82b6798..11ba081 100644 --- a/nvim/.config/nvim/lua/plugins/init.lua +++ b/nvim/.config/nvim/lua/plugins/init.lua @@ -1,6 +1,7 @@ require "plugins.main" require "plugins.solarized" require "plugins.cmp" +require "plugins.diffview" require "plugins.firenvim" require "plugins.gitsigns" require "plugins.indent" diff --git a/nvim/.config/nvim/lua/plugins/main.lua b/nvim/.config/nvim/lua/plugins/main.lua index ae67025..d5f05e3 100644 --- a/nvim/.config/nvim/lua/plugins/main.lua +++ b/nvim/.config/nvim/lua/plugins/main.lua @@ -68,6 +68,10 @@ return require('packer').startup(function(use) 'nvim-lua/plenary.nvim' }, } + use { + 'sindrets/diffview.nvim', + requires = 'nvim-lua/plenary.nvim' + } -- Language support use {