Skip to content

Commit a5e16ed

Browse files
authored
docs: update config documentation with actual defaults (#14)
1 parent a8226b7 commit a5e16ed

3 files changed

Lines changed: 265 additions & 4 deletions

File tree

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,31 @@ require("diffview").setup({
188188
enhanced_diff_hl = false, -- See |diffview-config-enhanced_diff_hl|
189189
git_cmd = { "git" }, -- The git executable followed by default args.
190190
hg_cmd = { "hg" }, -- The hg executable followed by default args.
191-
use_icons = true, -- Requires nvim-web-devicons
191+
rename_threshold = nil, -- Similarity threshold for rename detection (e.g. 40 for 40%). Nil uses git default (50%).
192+
use_icons = true, -- Requires nvim-web-devicons or mini.icons
192193
show_help_hints = true, -- Show hints for how to open the help panel
193194
watch_index = true, -- Update views and index buffers when the git index changes.
195+
hide_merge_artifacts = false, -- Hide merge artifact files (*.orig, *.BACKUP.*, *.BASE.*, *.LOCAL.*, *.REMOTE.*)
196+
auto_close_on_empty = false, -- Close diffview when the last file is staged/resolved
197+
diffopt = {}, -- Override diffopt settings while diffview is open. Restored on close.
198+
clean_up_buffers = false, -- Delete file buffers created by diffview on close.
194199
icons = { -- Only applies when use_icons is true.
195200
folder_closed = "",
196201
folder_open = "",
197202
},
203+
status_icons = { -- Configure icons for git status letters.
204+
["A"] = "A", -- Added
205+
["?"] = "?", -- Untracked
206+
["M"] = "M", -- Modified
207+
["R"] = "R", -- Renamed
208+
["C"] = "C", -- Copied
209+
["T"] = "T", -- Type changed
210+
["U"] = "U", -- Unmerged
211+
["X"] = "X", -- Unknown
212+
["D"] = "D", -- Deleted
213+
["B"] = "B", -- Broken
214+
["!"] = "!", -- Ignored
215+
},
198216
signs = {
199217
fold_closed = "",
200218
fold_open = "",
@@ -229,9 +247,15 @@ require("diffview").setup({
229247
disable_diagnostics = false, -- Temporarily disable diagnostics for diff buffers while in the view.
230248
winbar_info = false, -- See |diffview-config-view.x.winbar_info|
231249
},
250+
-- Layouts to cycle through with `cycle_layout` action.
251+
cycle_layouts = {
252+
default = { "diff2_horizontal", "diff2_vertical" },
253+
merge_tool = { "diff3_horizontal", "diff3_vertical", "diff3_mixed", "diff4_mixed", "diff1_plain" },
254+
},
232255
},
233256
file_panel = {
234257
listing_style = "tree", -- One of 'list' or 'tree'
258+
sort_file = nil, -- Custom file comparator: function(a_name, b_name, a_data, b_data) -> boolean
235259
tree_options = { -- Only applies when listing_style is 'tree'
236260
flatten_dirs = true, -- Flatten dirs that only contain one single dir
237261
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
@@ -241,12 +265,20 @@ require("diffview").setup({
241265
width = 35,
242266
win_opts = {},
243267
},
268+
show = true, -- Show the file panel when opening Diffview.
269+
always_show_sections = false, -- Always show Changes and Staged changes sections even when empty.
270+
show_branch_name = false, -- Show branch name in the file panel header.
244271
},
245272
file_history_panel = {
273+
stat_style = "number", -- "number" (e.g. "5, 3"), "bar" (e.g. "| 8 +++++---"), or "both".
274+
-- Ordered list of components to show for each commit entry.
275+
-- Available: "status", "files", "stats", "hash", "reflog", "ref", "subject", "author", "date"
276+
commit_format = { "status", "files", "stats", "hash", "reflog", "ref", "subject", "author", "date" },
246277
log_options = { -- See |diffview-config-log_options|
247278
git = {
248279
single_file = {
249-
diff_merges = "combined",
280+
diff_merges = "first-parent",
281+
follow = true,
250282
},
251283
multi_file = {
252284
diff_merges = "first-parent",
@@ -262,6 +294,8 @@ require("diffview").setup({
262294
height = 16,
263295
win_opts = {},
264296
},
297+
commit_subject_max_length = 72, -- Max length for commit subject display.
298+
date_format = "auto", -- Date format: "auto" | "relative" | "iso"
265299
},
266300
commit_log_panel = {
267301
win_config = {}, -- See |diffview-config-win_config|
@@ -283,6 +317,8 @@ require("diffview").setup({
283317
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
284318
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
285319
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
320+
{ "n", "gx", actions.open_file_external, { desc = "Open the file with default system application" } },
321+
{ "n", "<C-w>T", actions.open_in_new_tab, { desc = "Open diffview in a new tab" } },
286322
{ "n", "<leader>e", actions.focus_files, { desc = "Bring focus to the file panel" } },
287323
{ "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel." } },
288324
{ "n", "g<C-x>", actions.cycle_layout, { desc = "Cycle through available layouts." } },
@@ -350,6 +386,8 @@ require("diffview").setup({
350386
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
351387
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
352388
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
389+
{ "n", "gx", actions.open_file_external, { desc = "Open the file with default system application" } },
390+
{ "n", "<C-w>T", actions.open_in_new_tab, { desc = "Open diffview in a new tab" } },
353391
{ "n", "i", actions.listing_style, { desc = "Toggle between 'list' and 'tree' views" } },
354392
{ "n", "f", actions.toggle_flatten_dirs, { desc = "Flatten empty subdirectories in tree listing style" } },
355393
{ "n", "R", actions.refresh_files, { desc = "Update stats and entries in the file list" } },
@@ -368,6 +406,7 @@ require("diffview").setup({
368406
file_history_panel = {
369407
{ "n", "g!", actions.options, { desc = "Open the option panel" } },
370408
{ "n", "<C-A-d>", actions.open_in_diffview, { desc = "Open the entry under the cursor in a diffview" } },
409+
{ "n", "H", actions.diff_against_head, { desc = "Open a diffview comparing HEAD with the commit under the cursor" } },
371410
{ "n", "y", actions.copy_hash, { desc = "Copy the commit hash of the entry under the cursor" } },
372411
{ "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
373412
{ "n", "X", actions.restore_entry, { desc = "Restore file to the state from the selected entry" } },
@@ -394,6 +433,7 @@ require("diffview").setup({
394433
{ "n", "gf", actions.goto_file_edit, { desc = "Open the file in the previous tabpage" } },
395434
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
396435
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
436+
{ "n", "gx", actions.open_file_external, { desc = "Open the file with default system application" } },
397437
{ "n", "<leader>e", actions.focus_files, { desc = "Bring focus to the file panel" } },
398438
{ "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel" } },
399439
{ "n", "g<C-x>", actions.cycle_layout, { desc = "Cycle available layouts" } },

doc/diffview.txt

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ EXAMPLE CONFIGURATION WITH DEFAULT SETTINGS: |diffview.defaults|
401401

402402

403403

404+
diff_binaries *diffview-config-diff_binaries*
405+
Type: `boolean`, Default: `false`
406+
407+
Show diffs for binary files.
408+
404409
enhanced_diff_hl *diffview-config-enhanced_diff_hl*
405410
Type: `boolean`, Default: `false`
406411

@@ -439,6 +444,97 @@ hg_cmd *diffview-config-hg_cmd*
439444
If your Mercurial install bundles the `chg` binary, this can be
440445
configured here to have a significant performance boost.
441446

447+
rename_threshold *diffview-config-rename_threshold*
448+
Type: `integer?`, Default: `nil`
449+
450+
Similarity threshold for rename detection (e.g. 40 for 40%). When
451+
nil, uses the git default (50%).
452+
453+
use_icons *diffview-config-use_icons*
454+
Type: `boolean`, Default: `true`
455+
456+
Use file icons from nvim-web-devicons or mini.icons. Requires one
457+
of these plugins to be installed.
458+
459+
show_help_hints *diffview-config-show_help_hints*
460+
Type: `boolean`, Default: `true`
461+
462+
Show hints for how to open the help panel.
463+
464+
watch_index *diffview-config-watch_index*
465+
Type: `boolean`, Default: `true`
466+
467+
Update views and index buffers when the git index changes.
468+
469+
hide_merge_artifacts *diffview-config-hide_merge_artifacts*
470+
Type: `boolean`, Default: `false`
471+
472+
Hide merge artifact files (*.orig, *.BACKUP.*, *.BASE.*, *.LOCAL.*,
473+
*.REMOTE.*) from the file list.
474+
475+
auto_close_on_empty *diffview-config-auto_close_on_empty*
476+
Type: `boolean`, Default: `false`
477+
478+
Automatically close the Diffview when the last file is staged or
479+
resolved.
480+
481+
diffopt *diffview-config-diffopt*
482+
Type: `table`, Default: `{}`
483+
484+
Override |'diffopt'| settings while Diffview is open. Settings are
485+
restored on close. Available keys: `algorithm`, `context`,
486+
`indent_heuristic`, `iwhite`, `iwhiteall`, `iwhiteeol`, `iblank`,
487+
`icase`.
488+
489+
Example: >lua
490+
diffopt = { algorithm = "histogram", indent_heuristic = true }
491+
<
492+
493+
clean_up_buffers *diffview-config-clean_up_buffers*
494+
Type: `boolean`, Default: `false`
495+
496+
Delete file buffers created by Diffview when the view is closed.
497+
Only affects buffers that were not open before the Diffview was
498+
opened.
499+
500+
icons *diffview-config-icons*
501+
Type: `table`, Default: (see defaults)
502+
503+
Icons for folder states. Only applies when
504+
|diffview-config-use_icons| is true.
505+
506+
Fields: ~
507+
{folder_closed} (string)
508+
Icon for closed folders.
509+
510+
{folder_open} (string)
511+
Icon for open folders.
512+
513+
status_icons *diffview-config-status_icons*
514+
Type: `table`, Default: (see defaults)
515+
516+
Configure icons for git status letters. Each key is a git status
517+
letter and the value is the string to display in the file panel.
518+
519+
Default keys: `A` (added), `?` (untracked), `M` (modified),
520+
`R` (renamed), `C` (copied), `T` (type changed), `U` (unmerged),
521+
`X` (unknown), `D` (deleted), `B` (broken), `!` (ignored).
522+
523+
signs *diffview-config-signs*
524+
Type: `table`, Default: (see defaults)
525+
526+
Signs used in the file panel and file history panel.
527+
528+
Fields: ~
529+
{fold_closed} (string)
530+
Sign for closed folds.
531+
532+
{fold_open} (string)
533+
Sign for open folds.
534+
535+
{done} (string)
536+
Sign indicating completion/resolution.
537+
442538
view.x.layout *diffview-config-view.x.layout*
443539
Type: >
444540
"diff1_plain"
@@ -571,9 +667,108 @@ view.x.disable_diagnostics
571667
diagnostics are automatically enabled again when leaving or closing
572668
the view's tab page.
573669

670+
view.cycle_layouts *diffview-config-view.cycle_layouts*
671+
Type: `table`, Default: (see defaults)
672+
673+
Layouts to cycle through with the |diffview-actions-cycle_layout|
674+
action. Separate lists can be configured for the default view and
675+
the merge tool.
676+
677+
Fields: ~
678+
{default} (string[])
679+
Layouts to cycle through in the default view.
680+
Default: `{ "diff2_horizontal", "diff2_vertical" }`
681+
682+
{merge_tool} (string[])
683+
Layouts to cycle through in the merge tool.
684+
Default: >
685+
{ "diff3_horizontal", "diff3_vertical",
686+
"diff3_mixed", "diff4_mixed", "diff1_plain" }
687+
<
688+
689+
file_panel *diffview-config-file_panel*
690+
Type: `table`, Default: (see defaults)
691+
692+
Configuration for the file panel in Diffview.
693+
694+
Fields: ~
695+
{listing_style} ("tree"|"list")
696+
The listing style for the file panel. Default: `"tree"`
697+
698+
{sort_file} (function?)
699+
Custom file comparator function. Receives
700+
`(a_name, b_name, a_data, b_data)` and should return a
701+
boolean.
702+
703+
{tree_options} (table)
704+
Options for the tree listing style:
705+
• {flatten_dirs} (boolean) Flatten directories that only
706+
contain a single directory. Default: `true`
707+
• {folder_statuses} ("never"|"only_folded"|"always")
708+
Show folder statuses. Default: `"only_folded"`
709+
710+
{win_config} (table|function)
711+
See |diffview-config-win_config|.
712+
713+
{show} (boolean)
714+
Show the file panel when opening Diffview. Default: `true`
715+
716+
{always_show_sections} (boolean)
717+
Always show the Changes and Staged changes sections even
718+
when empty. Default: `false`
719+
720+
{show_branch_name} (boolean)
721+
Show branch name in the file panel header. Default: `false`
722+
723+
file_history_panel *diffview-config-file_history_panel*
724+
Type: `table`, Default: (see defaults)
725+
726+
Configuration for the file history panel.
727+
728+
Fields: ~
729+
{stat_style} ("number"|"bar"|"both")
730+
How to display file change stats. `"number"` shows e.g.
731+
"5, 3", `"bar"` shows e.g. "| 8 +++++---". Default:
732+
`"number"`
733+
734+
{commit_format} (string[])
735+
Ordered list of components to show for each commit entry.
736+
Available components: `"status"`, `"files"`, `"stats"`,
737+
`"hash"`, `"reflog"`, `"ref"`, `"subject"`, `"author"`,
738+
`"date"`.
739+
740+
{log_options} (table)
741+
See |diffview-config-log_options|.
742+
743+
{win_config} (table|function)
744+
See |diffview-config-win_config|.
745+
746+
{commit_subject_max_length} (integer)
747+
Maximum length for commit subject display.
748+
Default: `72`
749+
750+
{date_format} ("auto"|"relative"|"iso")
751+
Date format for commit entries. `"auto"` uses relative
752+
format for recent commits and ISO for older ones.
753+
Default: `"auto"`
754+
755+
commit_log_panel *diffview-config-commit_log_panel*
756+
Type: `table`, Default: (see defaults)
757+
758+
Configuration for the commit log panel (opened with the
759+
|diffview-actions-open_commit_log| action).
760+
761+
Fields: ~
762+
{win_config} (table|function)
763+
See |diffview-config-win_config|.
764+
574765
win_config *diffview-config-win_config*
575766
Type: `table | fun(): table`, Default: `{}`
576767

768+
This is a sub-field of the panel config tables
769+
(|diffview-config-file_panel|, |diffview-config-file_history_panel|,
770+
|diffview-config-commit_log_panel|), not a top-level config field.
771+
577772
This is used to configure the windows of the various panels in the
578773
plugin. If this is set to a function, it should return the config
579774
table when called (usually whenever the panel opens). If
@@ -662,6 +857,9 @@ win_config *diffview-config-win_config*
662857
log_options *diffview-config-log_options*
663858
Type: `table`, Default: (see defaults)
664859

860+
This is a sub-field of |diffview-config-file_history_panel|, not a
861+
top-level config field.
862+
665863
This table allows you to control the default options that are passed
666864
to git-log in order to produce the file history. The table is divided
667865
into the sub-tables `single_file`, and `multi_file`. This allows you

0 commit comments

Comments
 (0)