Skip to content

Commit cd6d295

Browse files
committed
chore(mappings): add desc to all mappings
1 parent 2320d17 commit cd6d295

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

lua/nvim-tree/keymap.lua

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,95 +185,95 @@ local DEFAULT_KEYMAPS = {
185185
key = "<C-r>",
186186
callback = Api.fs.rename_sub,
187187
desc = {
188-
long = "rename a file and omit the filename on input",
189-
short = "Rename - Omit Filename",
188+
long = "Rename a file or directory and omit the filename on input.",
189+
short = "Rename: Omit Filename",
190190
},
191191
},
192192
{
193193
key = "x",
194194
callback = Api.fs.cut,
195195
desc = {
196-
long = "add/remove file/directory to cut clipboard",
196+
long = "Cut file or directory to cut clipboard.",
197197
short = "Cut",
198198
},
199199
},
200200
{
201201
key = "c",
202202
callback = Api.fs.copy.node,
203203
desc = {
204-
long = "add/remove file/directory to copy clipboard",
204+
long = "Copy file or directory to copy clipboard.",
205205
short = "Copy",
206206
},
207207
},
208208
{
209209
key = "p",
210210
callback = Api.fs.paste,
211211
desc = {
212-
long = "paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation",
212+
long = "Paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation.",
213213
short = "Paste",
214214
},
215215
},
216216
{
217217
key = "y",
218218
callback = Api.fs.copy.filename,
219219
desc = {
220-
long = "copy name to system clipboard",
221-
short = "Copy File Name",
220+
long = "Copy name to system clipboard.",
221+
short = "Copy Name",
222222
},
223223
},
224224
{
225225
key = "Y",
226226
callback = Api.fs.copy.relative_path,
227227
desc = {
228-
long = "copy relative path to system clipboard",
228+
long = "Copy relative path to system clipboard.",
229229
short = "Copy Relative Path",
230230
},
231231
},
232232
{
233233
key = "gy",
234234
callback = Api.fs.copy.absolute_path,
235235
desc = {
236-
long = "copy absolute path to system clipboard",
236+
long = "Copy absolute path to system clipboard.",
237237
short = "Copy Absolute Path",
238238
},
239239
},
240240
{
241241
key = "[e",
242242
callback = Api.node.navigate.diagnostics.next,
243243
desc = {
244-
long = "go to next diagnostic item",
244+
long = "Go to next diagnostic item.",
245245
short = "Next Diagnostic",
246246
},
247247
},
248248
{
249249
key = "[c",
250250
callback = Api.node.navigate.git.next,
251251
desc = {
252-
long = "go to next git item",
252+
long = "Go to next git item.",
253253
short = "Next Git",
254254
},
255255
},
256256
{
257257
key = "]e",
258258
callback = Api.node.navigate.diagnostics.prev,
259259
desc = {
260-
long = "go to prev diagnostic item",
260+
long = "Go to prev diagnostic item.",
261261
short = "Prev Diagnostic",
262262
},
263263
},
264264
{
265265
key = "]c",
266266
callback = Api.node.navigate.git.prev,
267267
desc = {
268-
long = "go to prev git item",
268+
long = "Go to prev git item.",
269269
short = "Prev Git",
270270
},
271271
},
272272
{
273273
key = "-",
274274
callback = Api.tree.change_root_to_parent,
275275
desc = {
276-
long = "navigate up to the parent directory of the current file/directory",
276+
long = "Navigate up to the parent directory of the current file/directory.",
277277
short = "Up",
278278
},
279279
},
@@ -369,7 +369,7 @@ local DEFAULT_KEYMAPS = {
369369
key = "bmv",
370370
callback = Api.marks.bulk.move,
371371
desc = {
372-
long = "Move all bookmarked nodes into specified location",
372+
long = "Move all bookmarked nodes into specified location.",
373373
short = "Move Bookmarked",
374374
},
375375
},

lua/nvim-tree/renderer/help.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ function M.compute_lines()
7070

7171
local buf_keymaps = vim.api.nvim_buf_get_keymap(vim.api.nvim_get_current_buf(), "")
7272

73-
local processed = vim.tbl_map(function(bkm)
73+
local lines = vim.tbl_map(function(bkm)
7474
return { lhs = tidy_lhs(bkm.lhs), desc = bkm.desc }
7575
end, buf_keymaps)
7676

77-
table.sort(processed, function(a, b)
77+
table.sort(lines, function(a, b)
7878
return sort_lhs(a.lhs, b.lhs)
7979
end)
8080

81-
for _, p in pairs(processed) do
81+
for _, p in pairs(lines) do
8282
p.lhs = shorten_lhs(p.lhs)
8383
end
8484

8585
local num = 0
86-
for _, p in pairs(processed) do
86+
for _, p in pairs(lines) do
8787
num = num + 1
8888
local bind_string = string.format("%-6.6s %s", shorten_lhs(p.lhs), p.desc)
8989
table.insert(help_lines, bind_string)

scripts/generate_default_keymaps.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
-- write DEFAULT_KEYMAPS in various formats
55

6-
local max_key_help = 0
7-
local max_short_help = 0
6+
local max_key = 0
7+
local max_short = 0
8+
local max_callback = 0
89
local outs_help = {}
910

1011
for _, m in pairs(DEFAULT_KEYMAPS) do
@@ -13,22 +14,23 @@ for _, m in pairs(DEFAULT_KEYMAPS) do
1314
for _, key in ipairs(keys) do
1415
local out = {}
1516
out.key = key
16-
max_key_help = math.max(#out.key, max_key_help)
17+
max_key = math.max(#out.key, max_key)
1718
if first then
1819
out.short = m.desc.short
19-
max_short_help = math.max(#out.short, max_short_help)
20+
max_short = math.max(#out.short, max_short)
2021
out.long = m.desc.long
2122
first = false
2223
end
2324
table.insert(outs_help, out)
2425
end
26+
max_callback = math.max(#m.callback, max_callback)
2527
end
2628

2729
-- help
2830
local file = io.open("/tmp/DEFAULT_KEYMAPS.help", "w")
2931
io.output(file)
3032
io.write "\n"
31-
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key_help, max_key_help, max_short_help, max_short_help)
33+
local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key, max_key, max_short, max_short)
3234
for _, m in pairs(outs_help) do
3335
if not m.short then
3436
io.write(string.format("%s\n", m.key))
@@ -42,12 +44,19 @@ io.close(file)
4244
-- lua on_attach
4345
file = io.open("/tmp/DEFAULT_KEYMAPS.on_attach.lua", "w")
4446
io.output(file)
45-
io.write "local function on_attach(bufnr, mode, opts)\n"
46-
io.write "local Api = require('nvim-tree.api')\n"
47+
io.write "local Api = require('nvim-tree.api')\n\n"
48+
io.write "local function on_attach(bufnr)\n"
49+
fmt = string.format(
50+
" vim.keymap.set('n', %%-%d.%ds %%-%d.%ds { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = '%%s', })\n",
51+
max_key + 3,
52+
max_key + 3,
53+
max_callback + 1,
54+
max_callback + 1
55+
)
4756
for _, m in pairs(DEFAULT_KEYMAPS) do
4857
local keys = type(m.key) == "table" and m.key or { m.key }
4958
for _, key in ipairs(keys) do
50-
io.write(string.format(" vim.keymap.set(mode, '%s', %s, opts)\n", key, m.callback))
59+
io.write(string.format(fmt, "'" .. key .. "',", m.callback .. ",", m.desc.short))
5160
end
5261
end
5362
io.write "end\n"

0 commit comments

Comments
 (0)