Skip to content

Commit

Permalink
feat(keybinding): add nvcheatsheet.nvim (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Apr 10, 2024
1 parent 3f64ba3 commit 4da8d06
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/astrocommunity/keybinding/nvcheatsheet-nvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# nvcheatsheet.nvim

NvChad cheatsheet as a standalone neovim plugin

**Repository:** <https://github.com/smartinellimarco/nvcheatsheet.nvim>
46 changes: 46 additions & 0 deletions lua/astrocommunity/keybinding/nvcheatsheet-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
return {
"smartinellimarco/nvcheatsheet.nvim",
lazy = true,
dependencies = {
{
"AstroNvim/astrocore",
opts = {
mappings = {
n = {
["<F1>"] = { 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,
}

0 comments on commit 4da8d06

Please sign in to comment.