diff --git a/lua/nvim-tree/keymap.lua b/lua/nvim-tree/keymap.lua index bf3b051c..b6203a61 100644 --- a/lua/nvim-tree/keymap.lua +++ b/lua/nvim-tree/keymap.lua @@ -185,15 +185,15 @@ local DEFAULT_KEYMAPS = { key = "", callback = Api.fs.rename_sub, desc = { - long = "rename a file and omit the filename on input", - short = "Rename - Omit Filename", + long = "Rename a file or directory and omit the filename on input.", + short = "Rename: Omit Filename", }, }, { key = "x", callback = Api.fs.cut, desc = { - long = "add/remove file/directory to cut clipboard", + long = "Cut file or directory to cut clipboard.", short = "Cut", }, }, @@ -201,7 +201,7 @@ local DEFAULT_KEYMAPS = { key = "c", callback = Api.fs.copy.node, desc = { - long = "add/remove file/directory to copy clipboard", + long = "Copy file or directory to copy clipboard.", short = "Copy", }, }, @@ -209,7 +209,7 @@ local DEFAULT_KEYMAPS = { key = "p", callback = Api.fs.paste, desc = { - long = "paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation", + long = "Paste from clipboard; cut clipboard has precedence over copy; will prompt for confirmation.", short = "Paste", }, }, @@ -217,15 +217,15 @@ local DEFAULT_KEYMAPS = { key = "y", callback = Api.fs.copy.filename, desc = { - long = "copy name to system clipboard", - short = "Copy File Name", + long = "Copy name to system clipboard.", + short = "Copy Name", }, }, { key = "Y", callback = Api.fs.copy.relative_path, desc = { - long = "copy relative path to system clipboard", + long = "Copy relative path to system clipboard.", short = "Copy Relative Path", }, }, @@ -233,7 +233,7 @@ local DEFAULT_KEYMAPS = { key = "gy", callback = Api.fs.copy.absolute_path, desc = { - long = "copy absolute path to system clipboard", + long = "Copy absolute path to system clipboard.", short = "Copy Absolute Path", }, }, @@ -241,7 +241,7 @@ local DEFAULT_KEYMAPS = { key = "[e", callback = Api.node.navigate.diagnostics.next, desc = { - long = "go to next diagnostic item", + long = "Go to next diagnostic item.", short = "Next Diagnostic", }, }, @@ -249,7 +249,7 @@ local DEFAULT_KEYMAPS = { key = "[c", callback = Api.node.navigate.git.next, desc = { - long = "go to next git item", + long = "Go to next git item.", short = "Next Git", }, }, @@ -257,7 +257,7 @@ local DEFAULT_KEYMAPS = { key = "]e", callback = Api.node.navigate.diagnostics.prev, desc = { - long = "go to prev diagnostic item", + long = "Go to prev diagnostic item.", short = "Prev Diagnostic", }, }, @@ -265,7 +265,7 @@ local DEFAULT_KEYMAPS = { key = "]c", callback = Api.node.navigate.git.prev, desc = { - long = "go to prev git item", + long = "Go to prev git item.", short = "Prev Git", }, }, @@ -273,7 +273,7 @@ local DEFAULT_KEYMAPS = { key = "-", callback = Api.tree.change_root_to_parent, desc = { - long = "navigate up to the parent directory of the current file/directory", + long = "Navigate up to the parent directory of the current file/directory.", short = "Up", }, }, @@ -369,7 +369,7 @@ local DEFAULT_KEYMAPS = { key = "bmv", callback = Api.marks.bulk.move, desc = { - long = "Move all bookmarked nodes into specified location", + long = "Move all bookmarked nodes into specified location.", short = "Move Bookmarked", }, }, diff --git a/lua/nvim-tree/renderer/help.lua b/lua/nvim-tree/renderer/help.lua index 0289b814..13b73bdc 100644 --- a/lua/nvim-tree/renderer/help.lua +++ b/lua/nvim-tree/renderer/help.lua @@ -70,20 +70,20 @@ function M.compute_lines() local buf_keymaps = vim.api.nvim_buf_get_keymap(vim.api.nvim_get_current_buf(), "") - local processed = vim.tbl_map(function(bkm) + local lines = vim.tbl_map(function(bkm) return { lhs = tidy_lhs(bkm.lhs), desc = bkm.desc } end, buf_keymaps) - table.sort(processed, function(a, b) + table.sort(lines, function(a, b) return sort_lhs(a.lhs, b.lhs) end) - for _, p in pairs(processed) do + for _, p in pairs(lines) do p.lhs = shorten_lhs(p.lhs) end local num = 0 - for _, p in pairs(processed) do + for _, p in pairs(lines) do num = num + 1 local bind_string = string.format("%-6.6s %s", shorten_lhs(p.lhs), p.desc) table.insert(help_lines, bind_string) diff --git a/scripts/generate_default_keymaps.lua b/scripts/generate_default_keymaps.lua index daa46a7c..fd0d46bc 100644 --- a/scripts/generate_default_keymaps.lua +++ b/scripts/generate_default_keymaps.lua @@ -3,8 +3,9 @@ -- write DEFAULT_KEYMAPS in various formats -local max_key_help = 0 -local max_short_help = 0 +local max_key = 0 +local max_short = 0 +local max_callback = 0 local outs_help = {} for _, m in pairs(DEFAULT_KEYMAPS) do @@ -13,22 +14,23 @@ for _, m in pairs(DEFAULT_KEYMAPS) do for _, key in ipairs(keys) do local out = {} out.key = key - max_key_help = math.max(#out.key, max_key_help) + max_key = math.max(#out.key, max_key) if first then out.short = m.desc.short - max_short_help = math.max(#out.short, max_short_help) + max_short = math.max(#out.short, max_short) out.long = m.desc.long first = false end table.insert(outs_help, out) end + max_callback = math.max(#m.callback, max_callback) end -- help local file = io.open("/tmp/DEFAULT_KEYMAPS.help", "w") io.output(file) io.write "\n" -local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key_help, max_key_help, max_short_help, max_short_help) +local fmt = string.format("%%-%d.%ds %%-%d.%ds %%s\n", max_key, max_key, max_short, max_short) for _, m in pairs(outs_help) do if not m.short then io.write(string.format("%s\n", m.key)) @@ -42,12 +44,19 @@ io.close(file) -- lua on_attach file = io.open("/tmp/DEFAULT_KEYMAPS.on_attach.lua", "w") io.output(file) -io.write "local function on_attach(bufnr, mode, opts)\n" -io.write "local Api = require('nvim-tree.api')\n" +io.write "local Api = require('nvim-tree.api')\n\n" +io.write "local function on_attach(bufnr)\n" +fmt = string.format( + " vim.keymap.set('n', %%-%d.%ds %%-%d.%ds { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = '%%s', })\n", + max_key + 3, + max_key + 3, + max_callback + 1, + max_callback + 1 +) for _, m in pairs(DEFAULT_KEYMAPS) do local keys = type(m.key) == "table" and m.key or { m.key } for _, key in ipairs(keys) do - io.write(string.format(" vim.keymap.set(mode, '%s', %s, opts)\n", key, m.callback)) + io.write(string.format(fmt, "'" .. key .. "',", m.callback .. ",", m.desc.short)) end end io.write "end\n"