diff --git a/lua/chadrc.lua b/lua/chadrc.lua index 2b7ec23..1fea4ad 100644 --- a/lua/chadrc.lua +++ b/lua/chadrc.lua @@ -77,6 +77,7 @@ M.plugin_status = { autosave = false, -- to autosave files blankline = true, -- beautified blank lines bufferline = true, -- buffer shown as tabs + cheatsheet = true, -- fuzzy search your commands/keymappings colorizer = true, comment = true, -- universal commentor dashboard = false, -- a nice looking dashboard @@ -147,6 +148,10 @@ M.mappings.plugin = { moveUp = "", moveDown = "", }, + chadsheet = { + default_keys = "dk", + user_keys = "uk", + }, comment = { toggle = "/", -- trigger comment on a single/selected lines/number prefix }, diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 2bcd048..568b2af 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -131,6 +131,17 @@ M.bufferline = function() map("n", m.moveDown, "j") end +M.chadsheet = function() + local m = plugin_maps.chadsheet + + map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() ") + map( + "n", + m.user_keys, + ":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false } " + ) +end + M.comment = function() local m = plugin_maps.comment.toggle map("n", m, ":CommentToggle ") diff --git a/lua/default_config.lua b/lua/default_config.lua index bcc3cce..c8a9a36 100644 --- a/lua/default_config.lua +++ b/lua/default_config.lua @@ -82,6 +82,7 @@ M.plugin_status = { autosave = false, -- to autosave files blankline = true, -- beautified blank lines bufferline = true, -- buffer shown as tabs + cheatsheet = true, -- fuzzy search your commands/keymappings colorizer = true, comment = true, -- universal commentor dashboard = false, -- a nice looking dashboard @@ -147,6 +148,10 @@ M.mappings.plugin = { next_buffer = "", -- next buffer prev_buffer = "", -- previous buffer }, + chadsheet = { + default_keys = "dk", + user_keys = "uk", + }, comment = { toggle = "/", -- trigger comment on a single/selected lines/number prefix }, diff --git a/lua/plugins/configs/chadsheet.lua b/lua/plugins/configs/chadsheet.lua new file mode 100644 index 0000000..0a6cc02 --- /dev/null +++ b/lua/plugins/configs/chadsheet.lua @@ -0,0 +1,44 @@ +local present, chadsheet = pcall(require, "cheatsheet") + +if not present then + return +end + +local mappings = require("core.utils").load_config().mappings + +-- add user mappings to the cheetsheet +-- improve this function to not hardcode plugin +local function add_to_chadsheet(section, keymap, desc) + if section == "plugin" then + for sec, key in pairs(mappings.plugin) do + add_to_chadsheet(sec, key, sec) + end + else + if type(keymap) == "table" then + for sec, key in pairs(keymap) do + if type(sec) == "number" then + add_to_chadsheet(section, key, desc or section) + else + add_to_chadsheet(sec, key, desc or section) + end + end + else + chadsheet.add_cheat(section, keymap, desc or "Misc") + end + end +end + +for section, keymap in pairs(mappings) do + add_to_chadsheet(section, keymap) +end + +require("cheatsheet").setup { + + bundled_cheatsheets = { + enabled = { "default" }, + disabled = { "unicode", "nerd-fonts" }, + }, + + bundled_plugin_cheatsheets = false, + include_only_installed_plugins = true, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index cee6992..01456ce 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -272,7 +272,20 @@ return packer.startup(function() use { "nvim-telescope/telescope.nvim", cmd = "Telescope", + -- because cheatsheet is not activated by a teleacope command + module = "cheatsheet", requires = { + { + "sudormrfbin/cheatsheet.nvim", + disable = not plugin_status.cheatsheet, + after = "telescope.nvim", + config = function() + require "plugins.configs.chadsheet" + end, + setup = function() + require("core.mappings").chadsheet() + end, + }, { "nvim-telescope/telescope-fzf-native.nvim", run = "make",