Skip to content

Commit c6c51ab

Browse files
committed
feat: Add desc data to all keymaps. (fixes #239)
1 parent d2d9b18 commit c6c51ab

File tree

8 files changed

+343
-276
lines changed

8 files changed

+343
-276
lines changed

README.md

Lines changed: 91 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -231,92 +231,92 @@ require("diffview").setup({
231231
view = {
232232
-- The `view` bindings are active in the diff buffers, only when the current
233233
-- tabpage is a Diffview.
234-
["<tab>"] = actions.select_next_entry, -- Open the diff for the next file
235-
["<s-tab>"] = actions.select_prev_entry, -- Open the diff for the previous file
236-
["gf"] = actions.goto_file, -- Open the file in a new split in the previous tabpage
237-
["<C-w><C-f>"] = actions.goto_file_split, -- Open the file in a new split
238-
["<C-w>gf"] = actions.goto_file_tab, -- Open the file in a new tabpage
239-
["<leader>e"] = actions.focus_files, -- Bring focus to the file panel
240-
["<leader>b"] = actions.toggle_files, -- Toggle the file panel.
241-
["g<C-x>"] = actions.cycle_layout, -- Cycle through available layouts.
242-
["[x"] = actions.prev_conflict, -- In the merge_tool: jump to the previous conflict
243-
["]x"] = actions.next_conflict, -- In the merge_tool: jump to the next conflict
244-
["<leader>co"] = actions.conflict_choose("ours"), -- Choose the OURS version of a conflict
245-
["<leader>ct"] = actions.conflict_choose("theirs"), -- Choose the THEIRS version of a conflict
246-
["<leader>cb"] = actions.conflict_choose("base"), -- Choose the BASE version of a conflict
247-
["<leader>ca"] = actions.conflict_choose("all"), -- Choose all the versions of a conflict
248-
["dx"] = actions.conflict_choose("none"), -- Delete the conflict region
234+
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
235+
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
236+
{ "n", "gf", actions.goto_file, { desc = "Open the file in a new split in the previous tabpage" } },
237+
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
238+
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
239+
{ "n", "<leader>e", actions.focus_files, { desc = "Bring focus to the file panel" } },
240+
{ "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel." } },
241+
{ "n", "g<C-x>", actions.cycle_layout, { desc = "Cycle through available layouts." } },
242+
{ "n", "[x", actions.prev_conflict, { desc = "In the merge-tool: jump to the previous conflict" } },
243+
{ "n", "]x", actions.next_conflict, { desc = "In the merge-tool: jump to the next conflict" } },
244+
{ "n", "<leader>co", actions.conflict_choose("ours"), { desc = "Choose the OURS version of a conflict" } },
245+
{ "n", "<leader>ct", actions.conflict_choose("theirs"), { desc = "Choose the THEIRS version of a conflict" } },
246+
{ "n", "<leader>cb", actions.conflict_choose("base"), { desc = "Choose the BASE version of a conflict" } },
247+
{ "n", "<leader>ca", actions.conflict_choose("all"), { desc = "Choose all the versions of a conflict" } },
248+
{ "n", "dx", actions.conflict_choose("none"), { desc = "Delete the conflict region" } },
249249
},
250250
diff1 = { --[[ Mappings in single window diff layouts ]] },
251251
diff2 = { --[[ Mappings in 2-way diff layouts ]] },
252252
diff3 = {
253253
-- Mappings in 3-way diff layouts
254-
{ { "n", "x" }, "2do", actions.diffget("ours") }, -- Obtain the diff hunk from the OURS version of the file
255-
{ { "n", "x" }, "3do", actions.diffget("theirs") }, -- Obtain the diff hunk from the THEIRS version of the file
254+
{ { "n", "x" }, "2do", actions.diffget("ours"), { desc = "Obtain the diff hunk from the OURS version of the file" } },
255+
{ { "n", "x" }, "3do", actions.diffget("theirs"), { desc = "Obtain the diff hunk from the THEIRS version of the file" } },
256256
},
257257
diff4 = {
258258
-- Mappings in 4-way diff layouts
259-
{ { "n", "x" }, "1do", actions.diffget("base") }, -- Obtain the diff hunk from the BASE version of the file
260-
{ { "n", "x" }, "2do", actions.diffget("ours") }, -- Obtain the diff hunk from the OURS version of the file
261-
{ { "n", "x" }, "3do", actions.diffget("theirs") }, -- Obtain the diff hunk from the THEIRS version of the file
259+
{ { "n", "x" }, "1do", actions.diffget("base"), { desc = "Obtain the diff hunk from the BASE version of the file" } },
260+
{ { "n", "x" }, "2do", actions.diffget("ours"), { desc = "Obtain the diff hunk from the OURS version of the file" } },
261+
{ { "n", "x" }, "3do", actions.diffget("theirs"), { desc = "Obtain the diff hunk from the THEIRS version of the file" } },
262262
},
263263
file_panel = {
264-
["j"] = actions.next_entry, -- Bring the cursor to the next file entry
265-
["<down>"] = actions.next_entry,
266-
["k"] = actions.prev_entry, -- Bring the cursor to the previous file entry.
267-
["<up>"] = actions.prev_entry,
268-
["<cr>"] = actions.select_entry, -- Open the diff for the selected entry.
269-
["o"] = actions.select_entry,
270-
["<2-LeftMouse>"] = actions.select_entry,
271-
["-"] = actions.toggle_stage_entry, -- Stage / unstage the selected entry.
272-
["S"] = actions.stage_all, -- Stage all entries.
273-
["U"] = actions.unstage_all, -- Unstage all entries.
274-
["X"] = actions.restore_entry, -- Restore entry to the state on the left side.
275-
["L"] = actions.open_commit_log, -- Open the commit log panel.
276-
["<c-b>"] = actions.scroll_view(-0.25), -- Scroll the view up
277-
["<c-f>"] = actions.scroll_view(0.25), -- Scroll the view down
278-
["<tab>"] = actions.select_next_entry,
279-
["<s-tab>"] = actions.select_prev_entry,
280-
["gf"] = actions.goto_file,
281-
["<C-w><C-f>"] = actions.goto_file_split,
282-
["<C-w>gf"] = actions.goto_file_tab,
283-
["i"] = actions.listing_style, -- Toggle between 'list' and 'tree' views
284-
["f"] = actions.toggle_flatten_dirs, -- Flatten empty subdirectories in tree listing style.
285-
["R"] = actions.refresh_files, -- Update stats and entries in the file list.
286-
["<leader>e"] = actions.focus_files,
287-
["<leader>b"] = actions.toggle_files,
288-
["g<C-x>"] = actions.cycle_layout,
289-
["[x"] = actions.prev_conflict,
290-
["]x"] = actions.next_conflict,
264+
{ "n", "j", actions.next_entry, { desc = "Bring the cursor to the next file entry" } },
265+
{ "n", "<down>", actions.next_entry, { desc = "Bring the cursor to the next file entry" } },
266+
{ "n", "k", actions.prev_entry, { desc = "Bring the cursor to the previous file entry." } },
267+
{ "n", "<up>", actions.prev_entry, { desc = "Bring the cursor to the previous file entry." } },
268+
{ "n", "<cr>", actions.select_entry, { desc = "Open the diff for the selected entry." } },
269+
{ "n", "o", actions.select_entry, { desc = "Open the diff for the selected entry." } },
270+
{ "n", "<2-LeftMouse>", actions.select_entry, { desc = "Open the diff for the selected entry." } },
271+
{ "n", "-", actions.toggle_stage_entry, { desc = "Stage / unstage the selected entry." } },
272+
{ "n", "S", actions.stage_all, { desc = "Stage all entries." } },
273+
{ "n", "U", actions.unstage_all, { desc = "Unstage all entries." } },
274+
{ "n", "X", actions.restore_entry, { desc = "Restore entry to the state on the left side." } },
275+
{ "n", "L", actions.open_commit_log, { desc = "Open the commit log panel." } },
276+
{ "n", "<c-b>", actions.scroll_view(-0.25), { desc = "Scroll the view up" } },
277+
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
278+
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
279+
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
280+
{ "n", "gf", actions.goto_file, { desc = "Open the file in a new split in the previous tabpage" } },
281+
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
282+
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
283+
{ "n", "i", actions.listing_style, { desc = "Toggle between 'list' and 'tree' views" } },
284+
{ "n", "f", actions.toggle_flatten_dirs, { desc = "Flatten empty subdirectories in tree listing style." } },
285+
{ "n", "R", actions.refresh_files, { desc = "Update stats and entries in the file list." } },
286+
{ "n", "<leader>e", actions.focus_files, { desc = "Bring focus to the file panel" } },
287+
{ "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel" } },
288+
{ "n", "g<C-x>", actions.cycle_layout, { desc = "Cycle available layouts" } },
289+
{ "n", "[x", actions.prev_conflict, { desc = "Go to the previous conflict" } },
290+
{ "n", "]x", actions.next_conflict, { desc = "Go to the next conflict" } },
291291
},
292292
file_history_panel = {
293-
["g!"] = actions.options, -- Open the option panel
294-
["<C-A-d>"] = actions.open_in_diffview, -- Open the entry under the cursor in a diffview
295-
["y"] = actions.copy_hash, -- Copy the commit hash of the entry under the cursor
296-
["L"] = actions.open_commit_log,
297-
["zR"] = actions.open_all_folds,
298-
["zM"] = actions.close_all_folds,
299-
["j"] = actions.next_entry,
300-
["<down>"] = actions.next_entry,
301-
["k"] = actions.prev_entry,
302-
["<up>"] = actions.prev_entry,
303-
["<cr>"] = actions.select_entry,
304-
["o"] = actions.select_entry,
305-
["<2-LeftMouse>"] = actions.select_entry,
306-
["<c-b>"] = actions.scroll_view(-0.25),
307-
["<c-f>"] = actions.scroll_view(0.25),
308-
["<tab>"] = actions.select_next_entry,
309-
["<s-tab>"] = actions.select_prev_entry,
310-
["gf"] = actions.goto_file,
311-
["<C-w><C-f>"] = actions.goto_file_split,
312-
["<C-w>gf"] = actions.goto_file_tab,
313-
["<leader>e"] = actions.focus_files,
314-
["<leader>b"] = actions.toggle_files,
315-
["g<C-x>"] = actions.cycle_layout,
293+
{ "n", "g!", actions.options, { desc = "Open the option panel" } },
294+
{ "n", "<C-A-d>", actions.open_in_diffview, { desc = "Open the entry under the cursor in a diffview" } },
295+
{ "n", "y", actions.copy_hash, { desc = "Copy the commit hash of the entry under the cursor" } },
296+
{ "n", "L", actions.open_commit_log, { desc = "Show commit details" } },
297+
{ "n", "zR", actions.open_all_folds, { desc = "Expand all folds" } },
298+
{ "n", "zM", actions.close_all_folds, { desc = "Collapse all folds" } },
299+
{ "n", "j", actions.next_entry, { desc = "Bring the cursor to the next file entry" } },
300+
{ "n", "<down>", actions.next_entry, { desc = "Bring the cursor to the next file entry" } },
301+
{ "n", "k", actions.prev_entry, { desc = "Bring the cursor to the previous file entry." } },
302+
{ "n", "<up>", actions.prev_entry, { desc = "Bring the cursor to the previous file entry." } },
303+
{ "n", "<cr>", actions.select_entry, { desc = "Open the diff for the selected entry." } },
304+
{ "n", "o", actions.select_entry, { desc = "Open the diff for the selected entry." } },
305+
{ "n", "<2-LeftMouse>", actions.select_entry, { desc = "Open the diff for the selected entry." } },
306+
{ "n", "<c-b>", actions.scroll_view(-0.25), { desc = "Scroll the view up" } },
307+
{ "n", "<c-f>", actions.scroll_view(0.25), { desc = "Scroll the view down" } },
308+
{ "n", "<tab>", actions.select_next_entry, { desc = "Open the diff for the next file" } },
309+
{ "n", "<s-tab>", actions.select_prev_entry, { desc = "Open the diff for the previous file" } },
310+
{ "n", "gf", actions.goto_file, { desc = "Open the file in a new split in the previous tabpage" } },
311+
{ "n", "<C-w><C-f>", actions.goto_file_split, { desc = "Open the file in a new split" } },
312+
{ "n", "<C-w>gf", actions.goto_file_tab, { desc = "Open the file in a new tabpage" } },
313+
{ "n", "<leader>e", actions.focus_files, { desc = "Bring focus to the file panel" } },
314+
{ "n", "<leader>b", actions.toggle_files, { desc = "Toggle the file panel" } },
315+
{ "n", "g<C-x>", actions.cycle_layout, { desc = "Cycle available layouts" } },
316316
},
317317
option_panel = {
318-
["<tab>"] = actions.select_entry,
319-
["q"] = actions.close,
318+
{ "n", "<tab>", actions.select_entry, { desc = "Change the current option" } },
319+
{ "n", "q", actions.close, { desc = "Close the panel" } },
320320
},
321321
},
322322
})
@@ -369,13 +369,30 @@ either a vim command in the form of a string, or it can be a lua function:
369369
}
370370
```
371371

372-
To disable any single mapping without disabling them all, set its value to
372+
For more control (i.e. mappings for other modes), you can also define index
373+
values as list-like tables containing the arguments for `vim.keymap.set()`.
374+
This way you can also change all the `:map-arguments` with the only exception
375+
being the `buffer` field, as this will be overridden with the target buffer
376+
number:
377+
378+
```lua
379+
view = {
380+
-- Normal and visual mode mapping to vim command:
381+
{ { "n", "v" }, "<leader>a", "<Cmd>echom 'foo'<CR>", { silent = true } },
382+
-- Visual mode mapping to lua function:
383+
{ "v", "<leader>b", function() print("bar") end, { nowait = true } },
384+
}
385+
```
386+
387+
To disable any single mapping without disabling them all, set its `{rhs}` to
373388
`false`:
374389

375390
```lua
376391
view = {
377-
-- Disable the default mapping for <tab>:
392+
-- Disable the default normal mode mapping for `<tab>`:
378393
["<tab>"] = false,
394+
-- Disable the default visual mode mapping for `gf`:
395+
{ "x", "gf", false },
379396
}
380397
```
381398

doc/diffview.txt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,12 @@ keymaps *diffview-config-keymaps*
624624
|vim.keymap.set()|, so the {rhs} can be either a vim command in the
625625
form of a string, or it can be a lua function: >
626626
627-
view = {
628-
-- Vim command:
629-
["a"] = "<Cmd>echom 'foo'<CR>",
630-
-- Lua function:
631-
["b"] = function() print("bar") end,
632-
}
627+
view = {
628+
-- Vim command:
629+
["a"] = "<Cmd>echom 'foo'<CR>",
630+
-- Lua function:
631+
["b"] = function() print("bar") end,
632+
}
633633
<
634634

635635
For more control (i.e. mappings for other modes), you can also define
@@ -638,12 +638,12 @@ keymaps *diffview-config-keymaps*
638638
|:map-arguments| with the only exception being the `buffer` field, as
639639
this will be overridden with the target buffer number: >
640640
641-
view = {
642-
-- Normal and visual mode mapping to vim command:
643-
{ { "n", "v" }, "<leader>a", "<Cmd>echom 'foo'<CR>", { silent = true } },
644-
-- Visual mode mapping to lua function:
645-
{ "v", "<leader>b", function() print("bar") end, { nowait = true } },
646-
}
641+
view = {
642+
-- Normal and visual mode mapping to vim command:
643+
{ { "n", "v" }, "<leader>a", "<Cmd>echom 'foo'<CR>", { silent = true } },
644+
-- Visual mode mapping to lua function:
645+
{ "v", "<leader>b", function() print("bar") end, { nowait = true } },
646+
}
647647
<
648648

649649
To disable all the default mappings simply set: >
@@ -654,10 +654,13 @@ keymaps *diffview-config-keymaps*
654654
<
655655

656656
To disable any single mapping without disabling them all, set its
657-
value to `false`: >
657+
{rhs} to `false`: >
658658
659659
view = {
660+
-- Disable the default normal mode mapping for `<tab>`:
660661
["<tab>"] = false,
662+
-- Disable the default visual mode mapping for `gf`:
663+
{ "x", "gf", false },
661664
}
662665
<
663666

@@ -723,7 +726,7 @@ Actions~
723726
• The file under cursor
724727
• The file currently open
725728

726-
{options_panel}
729+
{option_panel}
727730
Panel used for interactively changing options in i.e. the
728731
FileHistoryView.
729732

@@ -1137,7 +1140,7 @@ These mappings are available in the file history panel buffer (the panel
11371140
listing the commits).
11381141

11391142
*diffview-maps-options*
1140-
g! Open the options panel.
1143+
g! Open the option panel.
11411144

11421145
*diffview-maps-open_in_diffview*
11431146
<C-d> Open the commit entry under the cursor in a Diffview.
@@ -1173,7 +1176,7 @@ o Open the diff for the selected item.
11731176
*diffview-maps-file-history-option-panel*
11741177
File history option panel maps~
11751178

1176-
These mappings are available from the file history options panel. The option
1179+
These mappings are available from the file history option panel. The option
11771180
panel will allow you to change the flags that will be passed to `git-log`. A
11781181
flag can be adjusted either by moving the cursor to its line followed by
11791182
pressing <Tab>, or by using the mappings that are shown directly in the

0 commit comments

Comments
 (0)