1 -- Single tabpage interface for easily cycling
2 -- through diffs for all modified files for any git rev.
3 -- https://github.com/sindrets/diffview.nvim
12 "DiffviewToggleFiles",
18 local actions = require("diffview.actions")
19 require("diffview").setup({
20 diff_binaries = false, -- Show diffs for binaries
21 enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
22 git_cmd = { "git" }, -- The git executable followed by default args.
23 hg_cmd = { "hg" }, -- The hg executable followed by default args.
24 use_icons = true, -- Requires nvim-web-devicons
25 show_help_hints = true, -- Show hints for how to open the help panel
26 watch_index = true, -- Update views and index buffers when the git index changes.
27 icons = { -- Only applies when use_icons is true.
37 -- Configure the layout and behavior of different types of views.
40 -- |'diff2_horizontal'
42 -- |'diff3_horizontal'
46 -- For more info, see |diffview-config-view.x.layout|.
48 -- Config for changed files, and staged files in diff views.
49 layout = "diff2_horizontal",
50 disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
51 winbar_info = false, -- See |diffview-config-view.x.winbar_info|
54 -- Config for conflicted files in diff views during a merge or rebase.
55 layout = "diff3_horizontal",
56 disable_diagnostics = true, -- Temporarily disable diagnostics for diff buffers while in the view.
57 winbar_info = true, -- See |diffview-config-view.x.winbar_info|
60 -- Config for changed files in file history views.
61 layout = "diff2_horizontal",
62 disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
63 winbar_info = false, -- See |diffview-config-view.x.winbar_info|
67 listing_style = "tree", -- One of 'list' or 'tree'
68 tree_options = { -- Only applies when listing_style is 'tree'
69 flatten_dirs = true, -- Flatten dirs that only contain one single dir
70 folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
72 win_config = { -- See |diffview-config-win_config|
78 file_history_panel = {
79 log_options = { -- See |diffview-config-log_options|
82 diff_merges = "combined",
85 diff_merges = "first-parent",
93 win_config = { -- See |diffview-config-win_config|
100 win_config = {}, -- See |diffview-config-win_config|
102 default_args = { -- Default args prepended to the arg-list for the listed commands
104 DiffviewFileHistory = {},
106 hooks = {}, -- See |diffview-config-hooks|
108 disable_defaults = false, -- Disable the default keymaps
110 -- The `view` bindings are active in the diff buffers, only when the current
111 -- tabpage is a Diffview.
115 actions.select_next_entry,
116 { desc = "Open the diff for the next file" },
121 actions.select_prev_entry,
122 { desc = "Open the diff for the previous file" },
127 actions.select_first_entry,
128 { desc = "Open the diff for the first file" },
133 actions.select_last_entry,
134 { desc = "Open the diff for the last file" },
139 actions.goto_file_edit,
140 { desc = "Open the file in the previous tabpage" },
145 actions.goto_file_split,
146 { desc = "Open the file in a new split" },
151 actions.goto_file_tab,
152 { desc = "Open the file in a new tabpage" },
158 { desc = "Bring focus to the file panel" },
160 { "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel." } },
164 actions.cycle_layout,
165 { desc = "Cycle through available layouts." },
170 actions.prev_conflict,
171 { desc = "In the merge-tool: jump to the previous conflict" },
176 actions.next_conflict,
177 { desc = "In the merge-tool: jump to the next conflict" },
182 actions.conflict_choose("ours"),
183 { desc = "Choose the OURS version of a conflict" },
188 actions.conflict_choose("theirs"),
189 { desc = "Choose the THEIRS version of a conflict" },
194 actions.conflict_choose("base"),
195 { desc = "Choose the BASE version of a conflict" },
200 actions.conflict_choose("all"),
201 { desc = "Choose all the versions of a conflict" },
206 actions.conflict_choose("none"),
207 { desc = "Delete the conflict region" },
212 actions.conflict_choose_all("ours"),
213 { desc = "Choose the OURS version of a conflict for the whole file" },
218 actions.conflict_choose_all("theirs"),
219 { desc = "Choose the THEIRS version of a conflict for the whole file" },
224 actions.conflict_choose_all("base"),
225 { desc = "Choose the BASE version of a conflict for the whole file" },
230 actions.conflict_choose_all("all"),
231 { desc = "Choose all the versions of a conflict for the whole file" },
236 actions.conflict_choose_all("none"),
237 { desc = "Delete the conflict region for the whole file" },
241 -- Mappings in single window diff layouts
242 { "n", "g?", actions.help({ "view", "diff1" }), { desc = "Open the help panel" } },
245 -- Mappings in 2-way diff layouts
246 { "n", "g?", actions.help({ "view", "diff2" }), { desc = "Open the help panel" } },
249 -- Mappings in 3-way diff layouts
253 actions.diffget("ours"),
254 { desc = "Obtain the diff hunk from the OURS version of the file" },
259 actions.diffget("theirs"),
260 { desc = "Obtain the diff hunk from the THEIRS version of the file" },
262 { "n", "g?", actions.help({ "view", "diff3" }), { desc = "Open the help panel" } },
265 -- Mappings in 4-way diff layouts
269 actions.diffget("base"),
270 { desc = "Obtain the diff hunk from the BASE version of the file" },
275 actions.diffget("ours"),
276 { desc = "Obtain the diff hunk from the OURS version of the file" },
281 actions.diffget("theirs"),
282 { desc = "Obtain the diff hunk from the THEIRS version of the file" },
284 { "n", "g?", actions.help({ "view", "diff4" }), { desc = "Open the help panel" } },
291 { desc = "Bring the cursor to the next file entry" },
297 { desc = "Bring the cursor to the next file entry" },
303 { desc = "Bring the cursor to the previous file entry" },
309 { desc = "Bring the cursor to the previous file entry" },
314 actions.select_entry,
315 { desc = "Open the diff for the selected entry" },
320 actions.select_entry,
321 { desc = "Open the diff for the selected entry" },
326 actions.select_entry,
327 { desc = "Open the diff for the selected entry" },
332 actions.select_entry,
333 { desc = "Open the diff for the selected entry" },
338 actions.toggle_stage_entry,
339 { desc = "Stage / unstage the selected entry" },
344 actions.toggle_stage_entry,
345 { desc = "Stage / unstage the selected entry" },
347 { "n", "S", actions.stage_all, { desc = "Stage all entries" } },
348 { "n", "U", actions.unstage_all, { desc = "Unstage all entries" } },
352 actions.restore_entry,
353 { desc = "Restore entry to the state on the left side" },
358 actions.open_commit_log,
359 { desc = "Open the commit log panel" },
361 { "n", "zo", actions.open_fold, { desc = "Expand fold" } },
362 { "n", "h", actions.close_fold, { desc = "Collapse fold" } },
363 { "n", "zc", actions.close_fold, { desc = "Collapse fold" } },
364 { "n", "za", actions.toggle_fold, { desc = "Toggle fold" } },
365 { "n", "zR", actions.open_all_folds, { desc = "Expand all folds" } },
366 { "n", "zM", actions.close_all_folds, { desc = "Collapse all folds" } },
367 { "n", "<c-b>", actions.scroll_view(-0.25), { desc = "Scroll the view up" } },
371 actions.scroll_view(0.25),
372 { desc = "Scroll the view down" },
377 actions.select_next_entry,
378 { desc = "Open the diff for the next file" },
383 actions.select_prev_entry,
384 { desc = "Open the diff for the previous file" },
389 actions.select_first_entry,
390 { desc = "Open the diff for the first file" },
395 actions.select_last_entry,
396 { desc = "Open the diff for the last file" },
401 actions.goto_file_edit,
402 { desc = "Open the file in the previous tabpage" },
407 actions.goto_file_split,
408 { desc = "Open the file in a new split" },
413 actions.goto_file_tab,
414 { desc = "Open the file in a new tabpage" },
419 actions.listing_style,
420 { desc = "Toggle between 'list' and 'tree' views" },
425 actions.toggle_flatten_dirs,
426 { desc = "Flatten empty subdirectories in tree listing style" },
431 actions.refresh_files,
432 { desc = "Update stats and entries in the file list" },
438 { desc = "Bring focus to the file panel" },
443 actions.toggle_files,
444 { desc = "Toggle the file panel" },
449 actions.cycle_layout,
450 { desc = "Cycle available layouts" },
455 actions.prev_conflict,
456 { desc = "Go to the previous conflict" },
461 actions.next_conflict,
462 { desc = "Go to the next conflict" },
464 { "n", "g?", actions.help("file_panel"), { desc = "Open the help panel" } },
468 actions.conflict_choose_all("ours"),
469 { desc = "Choose the OURS version of a conflict for the whole file" },
474 actions.conflict_choose_all("theirs"),
475 { desc = "Choose the THEIRS version of a conflict for the whole file" },
480 actions.conflict_choose_all("base"),
481 { desc = "Choose the BASE version of a conflict for the whole file" },
486 actions.conflict_choose_all("all"),
487 { desc = "Choose all the versions of a conflict for the whole file" },
492 actions.conflict_choose_all("none"),
493 { desc = "Delete the conflict region for the whole file" },
496 file_history_panel = {
497 { "n", "g!", actions.options, { desc = "Open the option panel" } },
501 actions.open_in_diffview,
502 { desc = "Open the entry under the cursor in a diffview" },
508 { desc = "Copy the commit hash of the entry under the cursor" },
510 { "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
514 actions.restore_entry,
515 { desc = "Restore file to the state from the selected entry" },
517 { "n", "zo", actions.open_fold, { desc = "Expand fold" } },
518 { "n", "zc", actions.close_fold, { desc = "Collapse fold" } },
519 { "n", "h", actions.close_fold, { desc = "Collapse fold" } },
520 { "n", "za", actions.toggle_fold, { desc = "Toggle fold" } },
521 { "n", "zR", actions.open_all_folds, { desc = "Expand all folds" } },
522 { "n", "zM", actions.close_all_folds, { desc = "Collapse all folds" } },
527 { desc = "Bring the cursor to the next file entry" },
533 { desc = "Bring the cursor to the next file entry" },
539 { desc = "Bring the cursor to the previous file entry" },
545 { desc = "Bring the cursor to the previous file entry" },
550 actions.select_entry,
551 { desc = "Open the diff for the selected entry" },
556 actions.select_entry,
557 { desc = "Open the diff for the selected entry" },
562 actions.select_entry,
563 { desc = "Open the diff for the selected entry" },
568 actions.select_entry,
569 { desc = "Open the diff for the selected entry" },
571 { "n", "<c-b>", actions.scroll_view(-0.25), { desc = "Scroll the view up" } },
572 { "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
576 actions.select_next_entry,
577 { desc = "Open the diff for the next file" },
582 actions.select_prev_entry,
583 { desc = "Open the diff for the previous file" },
588 actions.select_first_entry,
589 { desc = "Open the diff for the first file" },
594 actions.select_last_entry,
595 { desc = "Open the diff for the last file" },
600 actions.goto_file_edit,
601 { desc = "Open the file in the previous tabpage" },
606 actions.goto_file_split,
607 { desc = "Open the file in a new split" },
612 actions.goto_file_tab,
613 { desc = "Open the file in a new tabpage" },
619 { desc = "Bring focus to the file panel" },
621 { "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel" } },
622 { "n", "g<C-x>", actions.cycle_layout, { desc = "Cycle available layouts" } },
623 { "n", "g?", actions.help("file_history_panel"), { desc = "Open the help panel" } },
626 { "n", "<tab>", actions.select_entry, { desc = "Change the current option" } },
627 { "n", "q", actions.close, { desc = "Close the panel" } },
628 { "n", "g?", actions.help("option_panel"), { desc = "Open the help panel" } },
631 { "n", "q", actions.close, { desc = "Close help menu" } },
632 { "n", "<esc>", actions.close, { desc = "Close help menu" } },