From 4da8d06f480190feda6e2ca531adbf6fb222954c Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Wed, 10 Apr 2024 13:41:56 -0400 Subject: [PATCH] feat(keybinding): add `nvcheatsheet.nvim` (#861) --- .../keybinding/nvcheatsheet-nvim/README.md | 5 ++ .../keybinding/nvcheatsheet-nvim/init.lua | 46 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 lua/astrocommunity/keybinding/nvcheatsheet-nvim/README.md create mode 100644 lua/astrocommunity/keybinding/nvcheatsheet-nvim/init.lua diff --git a/lua/astrocommunity/keybinding/nvcheatsheet-nvim/README.md b/lua/astrocommunity/keybinding/nvcheatsheet-nvim/README.md new file mode 100644 index 000000000..1a5ce673a --- /dev/null +++ b/lua/astrocommunity/keybinding/nvcheatsheet-nvim/README.md @@ -0,0 +1,5 @@ +# nvcheatsheet.nvim + +NvChad cheatsheet as a standalone neovim plugin + +**Repository:** diff --git a/lua/astrocommunity/keybinding/nvcheatsheet-nvim/init.lua b/lua/astrocommunity/keybinding/nvcheatsheet-nvim/init.lua new file mode 100644 index 000000000..7e3f4e5ed --- /dev/null +++ b/lua/astrocommunity/keybinding/nvcheatsheet-nvim/init.lua @@ -0,0 +1,46 @@ +return { + "smartinellimarco/nvcheatsheet.nvim", + lazy = true, + dependencies = { + { + "AstroNvim/astrocore", + opts = { + mappings = { + n = { + [""] = { function() require("nvcheatsheet").toggle() end, desc = "Cheatsheet" }, + }, + }, + }, + }, + }, + opts = function(_, opts) + local mappings = vim.tbl_get(require("astrocore").plugin_opts "astrocore", "mappings", "n") + if mappings then + local heading_desc = { [""] = "General" } + if not opts.keymaps then opts.keymaps = {} end + for lhs, rhs in pairs(mappings) do + if type(rhs) == "table" then + local cmd, desc = rhs[1], rhs.name or rhs.desc + if desc and not cmd then heading_desc[lhs] = desc end + end + end + local headings = vim.tbl_keys(heading_desc) + for lhs, rhs in pairs(mappings) do + if type(rhs) == "table" then + local cmd, desc = rhs[1], rhs.name or rhs.desc + if desc and cmd then + local matched_heading = "" + for _, heading in ipairs(headings) do + if lhs:sub(1, #heading) == heading then + if #heading > #matched_heading then matched_heading = heading end + end + end + local heading = heading_desc[matched_heading] + if not opts.keymaps[heading] then opts.keymaps[heading] = {} end + table.insert(opts.keymaps[heading], { desc, lhs }) + end + end + end + end + end, +}