Skip to content

Commit 2320d17

Browse files
committed
chore(mappings): add desc to all mappings, show in help, reformat help
1 parent a847166 commit 2320d17

File tree

3 files changed

+118
-102
lines changed

3 files changed

+118
-102
lines changed

lua/nvim-tree/actions/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ local M = {
248248

249249
local function set_map_for(bufnr)
250250
local opts = { noremap = true, silent = true, nowait = true, buffer = bufnr }
251-
return function(mode, rhs)
251+
return function(mode, rhs, desc)
252252
return function(lhs)
253+
opts.desc = desc
253254
vim.keymap.set(mode or "n", lhs, rhs, opts)
254255
end
255256
end
@@ -266,7 +267,7 @@ function M.apply_mappings(bufnr)
266267
for _, b in pairs(M.mappings) do
267268
local rhs = b.cb or run_dispatch(b.action)
268269
if rhs then
269-
local setter = setter_for(b.mode, rhs)
270+
local setter = setter_for(b.mode, rhs, b.action)
270271

271272
local keys = type(b.key) == "table" and b.key or { b.key }
272273
for _, key in pairs(keys) do

lua/nvim-tree/keymap.lua

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,175 +8,176 @@ local DEFAULT_KEYMAPS = {
88
key = { "<CR>", "o", "<2-LeftMouse>" },
99
callback = Api.node.open.edit,
1010
desc = {
11-
long = "open a file or folder; root will cd to the above directory",
11+
long = "Open a file or directory; root will cd to the above directory.",
1212
short = "Open",
1313
},
1414
},
1515
{
1616
key = "<C-e>",
1717
callback = Api.node.open.replace_tree_buffer,
1818
desc = {
19-
long = "edit the file in place, effectively replacing the tree explorer",
19+
long = "Open file in place, effectively replacing the tree explorer.",
2020
short = "Open: In Place",
2121
},
2222
},
2323
{
2424
key = "O",
2525
callback = Api.node.open.no_window_picker,
2626
desc = {
27-
long = "same as (edit) with no window picker",
27+
long = "Open file with no window picker.",
2828
short = "Open: No Window Picker",
2929
},
3030
},
3131
{
3232
key = { "<C-]>", "<2-RightMouse>" },
3333
callback = Api.tree.change_root_to_node,
3434
desc = {
35-
long = "cd in the directory under the cursor",
36-
short = "cd",
35+
long = "cd in the directory under the cursor.",
36+
short = "CD",
3737
},
3838
},
3939
{
40-
key = "<C-v>",
40+
-- key = "<C-v>",
41+
key = "<ctrL-v>",
4142
callback = Api.node.open.vertical,
4243
desc = {
43-
long = "open the file in a vertical split",
44+
long = "Open file in a vertical split.",
4445
short = "Open: Vertical Split",
4546
},
4647
},
4748
{
4849
key = "<C-x>",
4950
callback = Api.node.open.horizontal,
5051
desc = {
51-
long = "open the file in a horizontal split",
52+
long = "Open file in a horizontal split.",
5253
short = "Open: Horizontal Split",
5354
},
5455
},
5556
{
5657
key = "<C-t>",
5758
callback = Api.node.open.tab,
5859
desc = {
59-
long = "open the file in a new tab",
60+
long = "Open file in a new tab.",
6061
short = "Open: New Tab",
6162
},
6263
},
6364
{
6465
key = "<",
6566
callback = Api.node.navigate.sibling.prev,
6667
desc = {
67-
long = "navigate to the previous sibling of current file/directory",
68+
long = "Navigate to the previous sibling.",
6869
short = "Previous Sibling",
6970
},
7071
},
7172
{
7273
key = ">",
7374
callback = Api.node.navigate.sibling.next,
7475
desc = {
75-
long = "navigate to the next sibling of current file/directory",
76+
long = "Navigate to the next sibling",
7677
short = "Next Sibling",
7778
},
7879
},
7980
{
8081
key = "P",
8182
callback = Api.node.navigate.parent,
8283
desc = {
83-
long = "move cursor to the parent directory",
84+
long = "Move cursor to the parent directory.",
8485
short = "Parent Directory",
8586
},
8687
},
8788
{
8889
key = "<BS>",
8990
callback = Api.node.navigate.parent_close,
9091
desc = {
91-
long = "close current opened directory or parent",
92-
short = "Close Folder",
92+
long = "Close current opened directory or parent.",
93+
short = "Close Directory",
9394
},
9495
},
9596
{
9697
key = "<Tab>",
9798
callback = Api.node.open.preview,
9899
desc = {
99-
long = "open the file as a preview (keeps the cursor in the tree)",
100+
long = "Open file as a preview (keeps the cursor in the tree).",
100101
short = "Open Preview",
101102
},
102103
},
103104
{
104105
key = "K",
105106
callback = Api.node.navigate.sibling.first,
106107
desc = {
107-
long = "navigate to the first sibling of current file/directory",
108+
long = "Navigate to the first sibling.",
108109
short = "First Sibling",
109110
},
110111
},
111112
{
112113
key = "J",
113114
callback = Api.node.navigate.sibling.last,
114115
desc = {
115-
long = "navigate to the last sibling of current file/directory",
116+
long = "Navigate to the last sibling.",
116117
short = "Last Sibling",
117118
},
118119
},
119120
{
120121
key = "I",
121122
callback = Api.tree.toggle_gitignore_filter,
122123
desc = {
123-
long = "toggle visibility of files/folders hidden via |git.ignore| option",
124+
long = "Toggle visibility of files/directories hidden via |git.ignore| option.",
124125
short = "Toggle Git Ignore",
125126
},
126127
},
127128
{
128129
key = "H",
129130
callback = Api.tree.toggle_hidden_filter,
130131
desc = {
131-
long = "toggle visibility of dotfiles via |filters.dotfiles| option",
132+
long = "Toggle visibility of dotfiles via |filters.dotfiles| option.",
132133
short = "Toggle Dotfiles",
133134
},
134135
},
135136
{
136137
key = "U",
137138
callback = Api.tree.toggle_custom_filter,
138139
desc = {
139-
long = "toggle visibility of files/folders hidden via |filters.custom| option",
140+
long = "Toggle visibility of files/directories hidden via |filters.custom| option.",
140141
short = "Toggle Hidden",
141142
},
142143
},
143144
{
144145
key = "R",
145146
callback = Api.tree.reload,
146147
desc = {
147-
long = "refresh the tree",
148+
long = "Refresh the tree.",
148149
short = "Refresh",
149150
},
150151
},
151152
{
152153
key = "a",
153154
callback = Api.fs.create,
154155
desc = {
155-
long = "add a file; leaving a trailing `/` will add a directory",
156+
long = "Create a file; leaving a trailing `/` will add a directory.",
156157
short = "Create",
157158
},
158159
},
159160
{
160161
key = "d",
161162
callback = Api.fs.remove,
162163
desc = {
163-
long = "delete a file (will prompt for confirmation)",
164+
long = "Delete a file, prompting for confirmation.",
164165
short = "Delete",
165166
},
166167
},
167168
{
168169
key = "D",
169170
callback = Api.fs.trash,
170171
desc = {
171-
long = "trash a file via |trash| option",
172+
long = "Trash a file via |trash| option.",
172173
short = "Trash",
173174
},
174175
},
175176
{
176177
key = "r",
177178
callback = Api.fs.rename,
178179
desc = {
179-
long = "rename a file",
180+
long = "Rename a file or directory.",
180181
short = "Rename",
181182
},
182183
},
@@ -280,87 +281,87 @@ local DEFAULT_KEYMAPS = {
280281
key = "s",
281282
callback = Api.node.run.system,
282283
desc = {
283-
long = "open a file with default system application or a folder with default file manager, using |system_open| option",
284+
long = "Open a file with default system application or a directory with default file manager, using |system_open| option.",
284285
short = "Run System",
285286
},
286287
},
287288
{
288289
key = "f",
289290
callback = Api.live_filter.start,
290291
desc = {
291-
long = "live filter nodes dynamically based on regex matching.",
292+
long = "Live filter nodes dynamically based on regex matching.",
292293
short = "Filter",
293294
},
294295
},
295296
{
296297
key = "F",
297298
callback = Api.live_filter.clear,
298299
desc = {
299-
long = "clear live filter",
300+
long = "Clear live filter.",
300301
short = "Clean Filter",
301302
},
302303
},
303304
{
304305
key = "q",
305306
callback = Api.tree.close,
306307
desc = {
307-
long = "close tree window",
308+
long = "Close tree window.",
308309
short = "Close",
309310
},
310311
},
311312
{
312313
key = "W",
313314
callback = Api.tree.collapse_all,
314315
desc = {
315-
long = "collapse the whole tree",
316+
long = "Collapse the whole tree.",
316317
short = "Collapse",
317318
},
318319
},
319320
{
320321
key = "E",
321322
callback = Api.tree.expand_all,
322323
desc = {
323-
long = "expand the whole tree, stopping after expanding |callbacks.expand_all.max_folder_discovery| folders; this might hang neovim for a while if running on a big folder",
324+
long = "Expand the whole tree, stopping after expanding |callbacks.expand_all.max_folder_discovery| directories; this might hang neovim for a while if running on a big directory.",
324325
short = "Expand All",
325326
},
326327
},
327328
{
328329
key = "S",
329330
callback = Api.tree.search_node,
330331
desc = {
331-
long = "prompt the user to enter a path and then expands the tree to match the path",
332+
long = "Prompt the user to enter a path and then expands the tree to match the path.",
332333
short = "Search",
333334
},
334335
},
335336
{
336337
key = ".",
337338
callback = Api.node.run.cmd,
338339
desc = {
339-
long = "enter vim command mode with the file the cursor is on",
340+
long = "Enter vim command mode with the file the cursor is on.",
340341
short = "Run Command",
341342
},
342343
},
343344
{
344345
key = "<C-k>",
345346
callback = Api.node.show_info_popup,
346347
desc = {
347-
long = "toggle a popup with file infos about the file under the cursor",
348+
long = "Toggle a popup with file info about the file under the cursor.",
348349
short = "Info",
349350
},
350351
},
351352
{
352353
key = "g?",
353354
callback = Api.tree.toggle_help,
354355
desc = {
355-
long = "toggle help",
356+
long = "Toggle help.",
356357
short = "Help",
357358
},
358359
},
359360
{
360361
key = "m",
361362
callback = Api.marks.toggle,
362363
desc = {
363-
long = "Toggle node in bookmarks",
364+
long = "Toggle node in bookmarks.",
364365
short = "Toggle Bookmark",
365366
},
366367
},
@@ -380,6 +381,7 @@ function M.set_keymaps(bufnr)
380381
for _, km in ipairs(M.keymaps) do
381382
local keys = type(km.key) == "table" and km.key or { km.key }
382383
for _, key in ipairs(keys) do
384+
opts.desc = km.desc.short
383385
vim.keymap.set("n", key, km.callback, opts)
384386
end
385387
end

0 commit comments

Comments
 (0)