]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/nvim/lua/plugins/diffview.lua
+user/op(nvim)(octo): enable
[julm/julm-nix.git] / home-manager / profiles / nvim / lua / plugins / diffview.lua
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
4 return {
5 "diffview.nvim",
6 cmd = {
7 "DiffviewClose",
8 "DiffviewFileHistory",
9 "DiffviewFocusFiles",
10 "DiffviewOpen",
11 "DiffviewRefresh",
12 "DiffviewToggleFiles",
13 },
14 load = function(name)
15 vim.cmd.packadd(name)
16 end,
17 after = function()
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.
28 folder_closed = "",
29 folder_open = "",
30 },
31 signs = {
32 fold_closed = "",
33 fold_open = "",
34 done = "✓",
35 },
36 view = {
37 -- Configure the layout and behavior of different types of views.
38 -- Available layouts:
39 -- 'diff1_plain'
40 -- |'diff2_horizontal'
41 -- |'diff2_vertical'
42 -- |'diff3_horizontal'
43 -- |'diff3_vertical'
44 -- |'diff3_mixed'
45 -- |'diff4_mixed'
46 -- For more info, see |diffview-config-view.x.layout|.
47 default = {
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|
52 },
53 merge_tool = {
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|
58 },
59 file_history = {
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|
64 },
65 },
66 file_panel = {
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'.
71 },
72 win_config = { -- See |diffview-config-win_config|
73 position = "left",
74 width = 35,
75 win_opts = {},
76 },
77 },
78 file_history_panel = {
79 log_options = { -- See |diffview-config-log_options|
80 git = {
81 single_file = {
82 diff_merges = "combined",
83 },
84 multi_file = {
85 diff_merges = "first-parent",
86 },
87 },
88 hg = {
89 single_file = {},
90 multi_file = {},
91 },
92 },
93 win_config = { -- See |diffview-config-win_config|
94 position = "bottom",
95 height = 16,
96 win_opts = {},
97 },
98 },
99 commit_log_panel = {
100 win_config = {}, -- See |diffview-config-win_config|
101 },
102 default_args = { -- Default args prepended to the arg-list for the listed commands
103 DiffviewOpen = {},
104 DiffviewFileHistory = {},
105 },
106 hooks = {}, -- See |diffview-config-hooks|
107 keymaps = {
108 disable_defaults = false, -- Disable the default keymaps
109 view = {
110 -- The `view` bindings are active in the diff buffers, only when the current
111 -- tabpage is a Diffview.
112 {
113 "n",
114 "<tab>",
115 actions.select_next_entry,
116 { desc = "Open the diff for the next file" },
117 },
118 {
119 "n",
120 "<s-tab>",
121 actions.select_prev_entry,
122 { desc = "Open the diff for the previous file" },
123 },
124 {
125 "n",
126 "[F",
127 actions.select_first_entry,
128 { desc = "Open the diff for the first file" },
129 },
130 {
131 "n",
132 "]F",
133 actions.select_last_entry,
134 { desc = "Open the diff for the last file" },
135 },
136 {
137 "n",
138 "gf",
139 actions.goto_file_edit,
140 { desc = "Open the file in the previous tabpage" },
141 },
142 {
143 "n",
144 "<C-w><C-f>",
145 actions.goto_file_split,
146 { desc = "Open the file in a new split" },
147 },
148 {
149 "n",
150 "<C-w>gf",
151 actions.goto_file_tab,
152 { desc = "Open the file in a new tabpage" },
153 },
154 {
155 "n",
156 "<leader>e",
157 actions.focus_files,
158 { desc = "Bring focus to the file panel" },
159 },
160 { "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel." } },
161 {
162 "n",
163 "g<C-x>",
164 actions.cycle_layout,
165 { desc = "Cycle through available layouts." },
166 },
167 {
168 "n",
169 "[x",
170 actions.prev_conflict,
171 { desc = "In the merge-tool: jump to the previous conflict" },
172 },
173 {
174 "n",
175 "]x",
176 actions.next_conflict,
177 { desc = "In the merge-tool: jump to the next conflict" },
178 },
179 {
180 "n",
181 "<leader>co",
182 actions.conflict_choose("ours"),
183 { desc = "Choose the OURS version of a conflict" },
184 },
185 {
186 "n",
187 "<leader>ct",
188 actions.conflict_choose("theirs"),
189 { desc = "Choose the THEIRS version of a conflict" },
190 },
191 {
192 "n",
193 "<leader>cb",
194 actions.conflict_choose("base"),
195 { desc = "Choose the BASE version of a conflict" },
196 },
197 {
198 "n",
199 "<leader>ca",
200 actions.conflict_choose("all"),
201 { desc = "Choose all the versions of a conflict" },
202 },
203 {
204 "n",
205 "dx",
206 actions.conflict_choose("none"),
207 { desc = "Delete the conflict region" },
208 },
209 {
210 "n",
211 "<leader>cO",
212 actions.conflict_choose_all("ours"),
213 { desc = "Choose the OURS version of a conflict for the whole file" },
214 },
215 {
216 "n",
217 "<leader>cT",
218 actions.conflict_choose_all("theirs"),
219 { desc = "Choose the THEIRS version of a conflict for the whole file" },
220 },
221 {
222 "n",
223 "<leader>cB",
224 actions.conflict_choose_all("base"),
225 { desc = "Choose the BASE version of a conflict for the whole file" },
226 },
227 {
228 "n",
229 "<leader>cA",
230 actions.conflict_choose_all("all"),
231 { desc = "Choose all the versions of a conflict for the whole file" },
232 },
233 {
234 "n",
235 "dX",
236 actions.conflict_choose_all("none"),
237 { desc = "Delete the conflict region for the whole file" },
238 },
239 },
240 diff1 = {
241 -- Mappings in single window diff layouts
242 { "n", "g?", actions.help({ "view", "diff1" }), { desc = "Open the help panel" } },
243 },
244 diff2 = {
245 -- Mappings in 2-way diff layouts
246 { "n", "g?", actions.help({ "view", "diff2" }), { desc = "Open the help panel" } },
247 },
248 diff3 = {
249 -- Mappings in 3-way diff layouts
250 {
251 { "n", "x" },
252 "2do",
253 actions.diffget("ours"),
254 { desc = "Obtain the diff hunk from the OURS version of the file" },
255 },
256 {
257 { "n", "x" },
258 "3do",
259 actions.diffget("theirs"),
260 { desc = "Obtain the diff hunk from the THEIRS version of the file" },
261 },
262 { "n", "g?", actions.help({ "view", "diff3" }), { desc = "Open the help panel" } },
263 },
264 diff4 = {
265 -- Mappings in 4-way diff layouts
266 {
267 { "n", "x" },
268 "1do",
269 actions.diffget("base"),
270 { desc = "Obtain the diff hunk from the BASE version of the file" },
271 },
272 {
273 { "n", "x" },
274 "2do",
275 actions.diffget("ours"),
276 { desc = "Obtain the diff hunk from the OURS version of the file" },
277 },
278 {
279 { "n", "x" },
280 "3do",
281 actions.diffget("theirs"),
282 { desc = "Obtain the diff hunk from the THEIRS version of the file" },
283 },
284 { "n", "g?", actions.help({ "view", "diff4" }), { desc = "Open the help panel" } },
285 },
286 file_panel = {
287 {
288 "n",
289 "j",
290 actions.next_entry,
291 { desc = "Bring the cursor to the next file entry" },
292 },
293 {
294 "n",
295 "<down>",
296 actions.next_entry,
297 { desc = "Bring the cursor to the next file entry" },
298 },
299 {
300 "n",
301 "k",
302 actions.prev_entry,
303 { desc = "Bring the cursor to the previous file entry" },
304 },
305 {
306 "n",
307 "<up>",
308 actions.prev_entry,
309 { desc = "Bring the cursor to the previous file entry" },
310 },
311 {
312 "n",
313 "<cr>",
314 actions.select_entry,
315 { desc = "Open the diff for the selected entry" },
316 },
317 {
318 "n",
319 "o",
320 actions.select_entry,
321 { desc = "Open the diff for the selected entry" },
322 },
323 {
324 "n",
325 "l",
326 actions.select_entry,
327 { desc = "Open the diff for the selected entry" },
328 },
329 {
330 "n",
331 "<2-LeftMouse>",
332 actions.select_entry,
333 { desc = "Open the diff for the selected entry" },
334 },
335 {
336 "n",
337 "-",
338 actions.toggle_stage_entry,
339 { desc = "Stage / unstage the selected entry" },
340 },
341 {
342 "n",
343 "s",
344 actions.toggle_stage_entry,
345 { desc = "Stage / unstage the selected entry" },
346 },
347 { "n", "S", actions.stage_all, { desc = "Stage all entries" } },
348 { "n", "U", actions.unstage_all, { desc = "Unstage all entries" } },
349 {
350 "n",
351 "X",
352 actions.restore_entry,
353 { desc = "Restore entry to the state on the left side" },
354 },
355 {
356 "n",
357 "L",
358 actions.open_commit_log,
359 { desc = "Open the commit log panel" },
360 },
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" } },
368 {
369 "n",
370 "<c-f>",
371 actions.scroll_view(0.25),
372 { desc = "Scroll the view down" },
373 },
374 {
375 "n",
376 "<tab>",
377 actions.select_next_entry,
378 { desc = "Open the diff for the next file" },
379 },
380 {
381 "n",
382 "<s-tab>",
383 actions.select_prev_entry,
384 { desc = "Open the diff for the previous file" },
385 },
386 {
387 "n",
388 "[F",
389 actions.select_first_entry,
390 { desc = "Open the diff for the first file" },
391 },
392 {
393 "n",
394 "]F",
395 actions.select_last_entry,
396 { desc = "Open the diff for the last file" },
397 },
398 {
399 "n",
400 "gf",
401 actions.goto_file_edit,
402 { desc = "Open the file in the previous tabpage" },
403 },
404 {
405 "n",
406 "<C-w><C-f>",
407 actions.goto_file_split,
408 { desc = "Open the file in a new split" },
409 },
410 {
411 "n",
412 "<C-w>gf",
413 actions.goto_file_tab,
414 { desc = "Open the file in a new tabpage" },
415 },
416 {
417 "n",
418 "i",
419 actions.listing_style,
420 { desc = "Toggle between 'list' and 'tree' views" },
421 },
422 {
423 "n",
424 "f",
425 actions.toggle_flatten_dirs,
426 { desc = "Flatten empty subdirectories in tree listing style" },
427 },
428 {
429 "n",
430 "R",
431 actions.refresh_files,
432 { desc = "Update stats and entries in the file list" },
433 },
434 {
435 "n",
436 "<leader>e",
437 actions.focus_files,
438 { desc = "Bring focus to the file panel" },
439 },
440 {
441 "n",
442 "<leader>b",
443 actions.toggle_files,
444 { desc = "Toggle the file panel" },
445 },
446 {
447 "n",
448 "g<C-x>",
449 actions.cycle_layout,
450 { desc = "Cycle available layouts" },
451 },
452 {
453 "n",
454 "[x",
455 actions.prev_conflict,
456 { desc = "Go to the previous conflict" },
457 },
458 {
459 "n",
460 "]x",
461 actions.next_conflict,
462 { desc = "Go to the next conflict" },
463 },
464 { "n", "g?", actions.help("file_panel"), { desc = "Open the help panel" } },
465 {
466 "n",
467 "<leader>cO",
468 actions.conflict_choose_all("ours"),
469 { desc = "Choose the OURS version of a conflict for the whole file" },
470 },
471 {
472 "n",
473 "<leader>cT",
474 actions.conflict_choose_all("theirs"),
475 { desc = "Choose the THEIRS version of a conflict for the whole file" },
476 },
477 {
478 "n",
479 "<leader>cB",
480 actions.conflict_choose_all("base"),
481 { desc = "Choose the BASE version of a conflict for the whole file" },
482 },
483 {
484 "n",
485 "<leader>cA",
486 actions.conflict_choose_all("all"),
487 { desc = "Choose all the versions of a conflict for the whole file" },
488 },
489 {
490 "n",
491 "dX",
492 actions.conflict_choose_all("none"),
493 { desc = "Delete the conflict region for the whole file" },
494 },
495 },
496 file_history_panel = {
497 { "n", "g!", actions.options, { desc = "Open the option panel" } },
498 {
499 "n",
500 "<C-A-d>",
501 actions.open_in_diffview,
502 { desc = "Open the entry under the cursor in a diffview" },
503 },
504 {
505 "n",
506 "y",
507 actions.copy_hash,
508 { desc = "Copy the commit hash of the entry under the cursor" },
509 },
510 { "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
511 {
512 "n",
513 "X",
514 actions.restore_entry,
515 { desc = "Restore file to the state from the selected entry" },
516 },
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" } },
523 {
524 "n",
525 "j",
526 actions.next_entry,
527 { desc = "Bring the cursor to the next file entry" },
528 },
529 {
530 "n",
531 "<down>",
532 actions.next_entry,
533 { desc = "Bring the cursor to the next file entry" },
534 },
535 {
536 "n",
537 "k",
538 actions.prev_entry,
539 { desc = "Bring the cursor to the previous file entry" },
540 },
541 {
542 "n",
543 "<up>",
544 actions.prev_entry,
545 { desc = "Bring the cursor to the previous file entry" },
546 },
547 {
548 "n",
549 "<cr>",
550 actions.select_entry,
551 { desc = "Open the diff for the selected entry" },
552 },
553 {
554 "n",
555 "o",
556 actions.select_entry,
557 { desc = "Open the diff for the selected entry" },
558 },
559 {
560 "n",
561 "l",
562 actions.select_entry,
563 { desc = "Open the diff for the selected entry" },
564 },
565 {
566 "n",
567 "<2-LeftMouse>",
568 actions.select_entry,
569 { desc = "Open the diff for the selected entry" },
570 },
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" } },
573 {
574 "n",
575 "<tab>",
576 actions.select_next_entry,
577 { desc = "Open the diff for the next file" },
578 },
579 {
580 "n",
581 "<s-tab>",
582 actions.select_prev_entry,
583 { desc = "Open the diff for the previous file" },
584 },
585 {
586 "n",
587 "[F",
588 actions.select_first_entry,
589 { desc = "Open the diff for the first file" },
590 },
591 {
592 "n",
593 "]F",
594 actions.select_last_entry,
595 { desc = "Open the diff for the last file" },
596 },
597 {
598 "n",
599 "gf",
600 actions.goto_file_edit,
601 { desc = "Open the file in the previous tabpage" },
602 },
603 {
604 "n",
605 "<C-w><C-f>",
606 actions.goto_file_split,
607 { desc = "Open the file in a new split" },
608 },
609 {
610 "n",
611 "<C-w>gf",
612 actions.goto_file_tab,
613 { desc = "Open the file in a new tabpage" },
614 },
615 {
616 "n",
617 "<leader>e",
618 actions.focus_files,
619 { desc = "Bring focus to the file panel" },
620 },
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" } },
624 },
625 option_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" } },
629 },
630 help_panel = {
631 { "n", "q", actions.close, { desc = "Close help menu" } },
632 { "n", "<esc>", actions.close, { desc = "Close help menu" } },
633 },
634 },
635 })
636 end,
637 }