diff --git a/README.md b/README.md index cdc8af91..fef08edb 100644 --- a/README.md +++ b/README.md @@ -39,146 +39,148 @@ require("lazy").setup({ - [x] treesitter auto-install seems broken. Switch to `ensure_installed` instead? - [x] list all plugins in readme - [ ] test all-the-things +- [x] auto-generate keymaps for README.md +- [x] auto-generate plugins for README.md -## Keymaps +## ⌨️ Keymaps ### General -| Key | Description | Mode | -| --- | --- | --- | -| ```` | Go to left window | **n** | -| ```` | Go to lower window | **n** | -| ```` | Go to upper window | **n** | -| ```` | Go to right window | **n** | -| ```` | Increase window height | **n** | -| ```` | Decrease window height | **n** | -| ```` | Decrease window width | **n** | -| ```` | Increase window width | **n** | -| ```` | Move down | **n**, **v**, **i** | -| ```` | Move up | **n**, **v**, **i** | -| ```` | Prev buffer | **n** | -| ```` | Next buffer | **n** | -| ``[p`` | Paste below | **n** | -| ``]p`` | Paste above | **n** | -| ```` | Escape and clear hlsearch | **i**, **n** | -| ``n`` | Next search result | **n**, **x**, **o** | -| ``N`` | Prev search result | **n**, **x**, **o** | -| ```` | Save file | **i**, **v**, **n**, **s** | -| ``l`` | Lazy | **n** | -| ``fn`` | New File | **n** | -| ``xl`` | Open Location List | **n** | -| ``xq`` | Open Quickfix List | **n** | -| ``tf`` | Format on Save | **n** | -| ``ts`` | Spelling | **n** | -| ``tw`` | Word Wrap | **n** | -| ``tn`` | Line Numbers | **n** | -| ``td`` | Diagnostics | **n** | -| ``tc`` | Conceal | **n** | -| ``gg`` | Lazygit (cwd) | **n** | -| ``gG`` | Lazygit (root dir) | **n** | -| ``qq`` | Quit all | **n** | -| ``hl`` | Highlight Groups at cursor | **n** | -| ``ot`` | Terminal (root dir) | **n** | -| ``oT`` | Terminal (cwd) | **n** | -| ```` | Enter Normal Mode | **t** | -| ``ww`` | other-window | **n** | -| ``wd`` | delete-window | **n** | -| ``w-`` | split-window-below | **n** | -| ``w\|`` | split-window-right | **n** | -| ``l`` | Last | **n** | -| ``f`` | First | **n** | -| ```` | New Tab | **n** | -| ``]`` | Next | **n** | -| ``d`` | Close | **n** | -| ``[`` | Previous | **n** | -| ``b]`` | Next Buffer | **n** | -| ``bb`` | Switch to Other Buffer | **n** | -| ``b[`` | Previous Buffer | **n** | -| ``` `` | Switch to Other Buffer | **n** | +| Key | Description | Mode | +| -------------------- | -------------------------- | -------------------------- | +| `` | Go to left window | **n** | +| `` | Go to lower window | **n** | +| `` | Go to upper window | **n** | +| `` | Go to right window | **n** | +| `` | Increase window height | **n** | +| `` | Decrease window height | **n** | +| `` | Decrease window width | **n** | +| `` | Increase window width | **n** | +| `` | Move down | **n**, **v**, **i** | +| `` | Move up | **n**, **v**, **i** | +| `` | Prev buffer | **n** | +| `` | Next buffer | **n** | +| `[p` | Paste below | **n** | +| `]p` | Paste above | **n** | +| `` | Escape and clear hlsearch | **i**, **n** | +| `n` | Next search result | **n**, **x**, **o** | +| `N` | Prev search result | **n**, **x**, **o** | +| `` | Save file | **i**, **v**, **n**, **s** | +| `l` | Lazy | **n** | +| `fn` | New File | **n** | +| `xl` | Open Location List | **n** | +| `xq` | Open Quickfix List | **n** | +| `tf` | Toggle Format on Save | **n** | +| `ts` | Toggle Spelling | **n** | +| `tw` | Toggle Word Wrap | **n** | +| `tn` | Toggle Line Numbers | **n** | +| `td` | Toggle Diagnostics | **n** | +| `tc` | Toggle Conceal | **n** | +| `gg` | Lazygit (cwd) | **n** | +| `gG` | Lazygit (root dir) | **n** | +| `qq` | Quit all | **n** | +| `hl` | Highlight Groups at cursor | **n** | +| `ot` | Terminal (root dir) | **n** | +| `oT` | Terminal (cwd) | **n** | +| `` | Enter Normal Mode | **t** | +| `ww` | other-window | **n** | +| `wd` | delete-window | **n** | +| `w-` | split-window-below | **n** | +| `w\|` | split-window-right | **n** | +| `l` | Last | **n** | +| `f` | First | **n** | +| `` | New Tab | **n** | +| `]` | Next | **n** | +| `d` | Close | **n** | +| `[` | Previous | **n** | +| `b]` | Next Buffer | **n** | +| `bb` | Switch to Other Buffer | **n** | +| `b[` | Previous Buffer | **n** | +| `` ` `` | Switch to Other Buffer | **n** | ### LSP -| Key | Description | Mode | -| --- | --- | --- | -| ``cd`` | Line Diagnostics | **n** | -| ``cl`` | Lsp Info | **n** | -| ``xd`` | Telescope Diagnostics | **n** | -| ``gd`` | Goto Definition | **n** | -| ``gr`` | References | **n** | -| ``gD`` | Goto Declaration | **n** | -| ``gI`` | Goto Implementation | **n** | -| ``gt`` | Goto Type Definition | **n** | -| ``K`` | Hover | **n** | -| ``gK`` | Signature Help | **n** | -| ``[d`` | Next Diagnostic | **n** | -| ``]d`` | Prev Diagnostic | **n** | -| ``]e`` | Next Error | **n** | -| ``[e`` | Prev Error | **n** | -| ``]w`` | Next Warning | **n** | -| ``[w`` | Prev Warning | **n** | -| ``ca`` | Code Action | **n**, **v** | -| ``cf`` | Format Document | **n** | -| ``cf`` | Format Range | **v** | -| ``cr`` | Rename | **n** | +| Key | Description | Mode | +| ------------ | --------------------- | ------------ | +| `cd` | Line Diagnostics | **n** | +| `cl` | Lsp Info | **n** | +| `xd` | Telescope Diagnostics | **n** | +| `gd` | Goto Definition | **n** | +| `gr` | References | **n** | +| `gD` | Goto Declaration | **n** | +| `gI` | Goto Implementation | **n** | +| `gt` | Goto Type Definition | **n** | +| `K` | Hover | **n** | +| `gK` | Signature Help | **n** | +| `[d` | Next Diagnostic | **n** | +| `]d` | Prev Diagnostic | **n** | +| `]e` | Next Error | **n** | +| `[e` | Prev Error | **n** | +| `]w` | Next Warning | **n** | +| `[w` | Prev Warning | **n** | +| `ca` | Code Action | **n**, **v** | +| `cf` | Format Document | **n** | +| `cf` | Format Range | **v** | +| `cr` | Rename | **n** | ### Plugins -| Key | Description | Mode | -| --- | --- | --- | -| ``cm`` | [mason.nvim](https://github.com/williamboman/mason.nvim.git) Mason | **n** | -| ``bd`` | [mini.bufremove](https://github.com/echasnovski/mini.bufremove.git) Delete Buffer | **n** | -| ``bD`` | [mini.bufremove](https://github.com/echasnovski/mini.bufremove.git) Delete Buffer (Force) | **n** | -| ``ft`` | [neo-tree.nvim](https://github.com/nvim-neo-tree/neo-tree.nvim.git) NeoTree (root dir) | **n** | -| ``fT`` | [neo-tree.nvim](https://github.com/nvim-neo-tree/neo-tree.nvim.git) NeoTree (cwd) | **n** | -| ```` | [noice.nvim](https://github.com/folke/noice.nvim.git) Redirect Cmdline | **c** | -| ``nl`` | [noice.nvim](https://github.com/folke/noice.nvim.git) Noice Last Message | **n** | -| ``nh`` | [noice.nvim](https://github.com/folke/noice.nvim.git) Noice History | **n** | -| ``na`` | [noice.nvim](https://github.com/folke/noice.nvim.git) Noice All | **n** | -| ``nd`` | [nvim-notify](https://github.com/rcarriga/nvim-notify.git) Delete all Notifications | **n** | -| ``sr`` | [nvim-spectre](https://github.com/windwp/nvim-spectre.git) Replace in files (Spectre) | **n** | -| ``qs`` | [persistence.nvim](https://github.com/folke/persistence.nvim.git) Restore Session | **n** | -| ``ql`` | [persistence.nvim](https://github.com/folke/persistence.nvim.git) Restore Last Session | **n** | -| ``qd`` | [persistence.nvim](https://github.com/folke/persistence.nvim.git) Don't Save Current Session | **n** | -| ``/`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find in Files (Grep) | **n** | -| ```` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find Files (root dir) | **n** | -| ``fb`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Buffers | **n** | -| ``ff`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find Files (root dir) | **n** | -| ``fF`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find Files (cwd) | **n** | -| ``fr`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Recent | **n** | -| ``gc`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) commits | **n** | -| ``gs`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) status | **n** | -| ``ha`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Auto Commands | **n** | -| ``hc`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Commands | **n** | -| ``hf`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) File Types | **n** | -| ``hh`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Help Pages | **n** | -| ``hk`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Key Maps | **n** | -| ``hm`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Man Pages | **n** | -| ``ho`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Options | **n** | -| ``hs`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Search Highlight Groups | **n** | -| ``ht`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Telescope | **n** | -| ``sb`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Buffer | **n** | -| ``sc`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Command History | **n** | -| ``sg`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Grep (root dir) | **n** | -| ``sG`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Grep (cwd) | **n** | -| ``sm`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Jump to Mark | **n** | -| ``,`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Switch Buffer | **n** | -| ``:`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Command History | **n** | -| ``ss`` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Goto Symbol | **n** | -| ``]t`` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Next todo comment | **n** | -| ``[t`` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Previous todo comment | **n** | -| ``xt`` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Todo Trouble | **n** | -| ``xtt`` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Todo Trouble | **n** | -| ``xT`` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Todo Telescope | **n** | -| ``xx`` | [trouble.nvim](https://github.com/folke/trouble.nvim.git) Document Diagnostics (Trouble) | **n** | -| ``xX`` | [trouble.nvim](https://github.com/folke/trouble.nvim.git) Workspace Diagnostics (Trouble) | **n** | -| ``]]`` | [vim-illuminate](https://github.com/RRethy/vim-illuminate.git) Next Reference | **n** | -| ``[[`` | [vim-illuminate](https://github.com/RRethy/vim-illuminate.git) Prev Reference | **n** | +| Key | Description | Mode | +| ----------------- | ---------------------------------------------------------------------------------------------- | ----- | +| `cm` | [mason.nvim](https://github.com/williamboman/mason.nvim.git) Mason | **n** | +| `bd` | [mini.bufremove](https://github.com/echasnovski/mini.bufremove.git) Delete Buffer | **n** | +| `bD` | [mini.bufremove](https://github.com/echasnovski/mini.bufremove.git) Delete Buffer (Force) | **n** | +| `ft` | [neo-tree.nvim](https://github.com/nvim-neo-tree/neo-tree.nvim.git) NeoTree (root dir) | **n** | +| `fT` | [neo-tree.nvim](https://github.com/nvim-neo-tree/neo-tree.nvim.git) NeoTree (cwd) | **n** | +| `` | [noice.nvim](https://github.com/folke/noice.nvim.git) Redirect Cmdline | **c** | +| `nl` | [noice.nvim](https://github.com/folke/noice.nvim.git) Noice Last Message | **n** | +| `nh` | [noice.nvim](https://github.com/folke/noice.nvim.git) Noice History | **n** | +| `na` | [noice.nvim](https://github.com/folke/noice.nvim.git) Noice All | **n** | +| `nd` | [nvim-notify](https://github.com/rcarriga/nvim-notify.git) Delete all Notifications | **n** | +| `sr` | [nvim-spectre](https://github.com/windwp/nvim-spectre.git) Replace in files (Spectre) | **n** | +| `qs` | [persistence.nvim](https://github.com/folke/persistence.nvim.git) Restore Session | **n** | +| `ql` | [persistence.nvim](https://github.com/folke/persistence.nvim.git) Restore Last Session | **n** | +| `qd` | [persistence.nvim](https://github.com/folke/persistence.nvim.git) Don't Save Current Session | **n** | +| `/` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find in Files (Grep) | **n** | +| `` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find Files (root dir) | **n** | +| `fb` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Buffers | **n** | +| `ff` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find Files (root dir) | **n** | +| `fF` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Find Files (cwd) | **n** | +| `fr` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Recent | **n** | +| `gc` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) commits | **n** | +| `gs` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) status | **n** | +| `ha` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Auto Commands | **n** | +| `hc` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Commands | **n** | +| `hf` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) File Types | **n** | +| `hh` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Help Pages | **n** | +| `hk` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Key Maps | **n** | +| `hm` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Man Pages | **n** | +| `ho` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Options | **n** | +| `hs` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Search Highlight Groups | **n** | +| `ht` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Telescope | **n** | +| `sb` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Buffer | **n** | +| `sc` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Command History | **n** | +| `sg` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Grep (root dir) | **n** | +| `sG` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Grep (cwd) | **n** | +| `sm` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Jump to Mark | **n** | +| `,` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Switch Buffer | **n** | +| `:` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Command History | **n** | +| `ss` | [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim.git) Goto Symbol | **n** | +| `]t` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Next todo comment | **n** | +| `[t` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Previous todo comment | **n** | +| `xt` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Todo Trouble | **n** | +| `xtt` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Todo Trouble | **n** | +| `xT` | [todo-comments.nvim](https://github.com/folke/todo-comments.nvim.git) Todo Telescope | **n** | +| `xx` | [trouble.nvim](https://github.com/folke/trouble.nvim.git) Document Diagnostics (Trouble) | **n** | +| `xX` | [trouble.nvim](https://github.com/folke/trouble.nvim.git) Workspace Diagnostics (Trouble) | **n** | +| `]]` | [vim-illuminate](https://github.com/RRethy/vim-illuminate.git) Next Reference | **n** | +| `[[` | [vim-illuminate](https://github.com/RRethy/vim-illuminate.git) Prev Reference | **n** | -## Plugins +## 📦 Plugins diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 15dafb8a..a6d379ba 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -73,13 +73,13 @@ vim.keymap.set("n", "xq", "copen", { desc = "Open Quickfix List -- stylua: ignore start -- toggle options -vim.keymap.set("n", "tf", require("lazyvim.plugins.lsp.format").toggle, { desc = "Format on Save" }) -vim.keymap.set("n", "ts", function() util.toggle("spell") end, { desc = "Spelling" }) -vim.keymap.set("n", "tw", function() util.toggle("wrap") end, { desc = "Word Wrap" }) -vim.keymap.set("n", "tn", function() util.toggle("relativenumber", true) util.toggle("number") end, { desc = "Line Numbers" }) -vim.keymap.set("n", "td", util.toggle_diagnostics, { desc = "Diagnostics" }) +vim.keymap.set("n", "tf", require("lazyvim.plugins.lsp.format").toggle, { desc = "Toggle format on Save" }) +vim.keymap.set("n", "ts", function() util.toggle("spell") end, { desc = "Toggle Spelling" }) +vim.keymap.set("n", "tw", function() util.toggle("wrap") end, { desc = "Toggle Word Wrap" }) +vim.keymap.set("n", "tn", function() util.toggle("relativenumber", true) util.toggle("number") end, { desc = "Toggle Line Numbers" }) +vim.keymap.set("n", "td", util.toggle_diagnostics, { desc = "Toggle Diagnostics" }) local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 -vim.keymap.set("n", "tc", function() util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Conceal" }) +vim.keymap.set("n", "tc", function() util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Toggle Conceal" }) -- lazygit vim.keymap.set("n", "gg", function() require("lazyvim.util").float_term({ "lazygit" }) end, { desc = "Lazygit (cwd)" }) diff --git a/lua/lazyvim/util/build.lua b/lua/lazyvim/util/build.lua new file mode 100644 index 00000000..21525e43 --- /dev/null +++ b/lua/lazyvim/util/build.lua @@ -0,0 +1,98 @@ +-- Ugly code to generate some things for the readme + +local M = {} + +function M.keymaps() + local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h:h") + local keymap_set = vim.keymap.set + ---@type table + local keymaps = {} + ---@type string + local group = nil + ---@type string[] + local groups = {} + local function map(mode, lhs, rhs, opts) + if not (opts and opts.desc) then + return + end + if not vim.tbl_contains(groups, group) then + groups[#groups + 1] = group + end + mode = mode == nil and { "n", "v", "o" } or type(mode) == "string" and { mode } or mode + local desc = opts and opts.desc or "" + local key = lhs .. desc .. group + if keymaps[key] then + vim.list_extend(keymaps[key].mode, mode) + else + keymaps[key] = { mode = mode, keys = lhs, desc = desc, i = vim.tbl_count(keymaps), group = group } + end + end + vim.keymap.set = map + + group = "General" + dofile(root .. "/lua/lazyvim/config/keymaps.lua") + group = "LSP" + local lsp = dofile(root .. "/lua/lazyvim/plugins/lsp/keymaps.lua") + lsp.has = function() + return true + end + lsp.on_attach({ name = "foobar" }) + + vim.keymap.set = keymap_set + + group = "Plugins" + + require("lazy.util").foreach(require("lazy.core.config").plugins, function(name, plugin) + for _, key in ipairs(plugin.keys or {}) do + if type(key) == "table" and key.desc then + local desc = key.desc or "" + desc = ("[%s](%s)"):format(plugin.name, plugin.url) .. " " .. desc + map(key.mode or "n", key[1], key[2], { desc = desc }) + end + end + end) + + ---@type string[] + local lines = {} + + for _, group in ipairs(groups) do + lines[#lines + 1] = "### " .. group + lines[#lines + 1] = "" + vim.list_extend(lines, { "| Key | Description | Mode |", "| --- | --- | --- |" }) + local mappings = vim.tbl_filter(function(m) + return m.group == group and m.desc + end, keymaps) + + table.sort(mappings, function(a, b) + return a.i < b.i + end) + + for _, m in ipairs(mappings) do + lines[#lines + 1] = "| ``" + .. m.keys:gsub("|", "\\|"):gsub("`$", "` ") + .. "`` | " + .. m.desc + .. " | " + .. table.concat( + vim.tbl_map(function(mode) + return "**" .. mode .. "**" + end, m.mode), + ", " + ) + .. " |" + end + lines[#lines + 1] = "" + end + return table.concat(lines, "\n") +end + +function M.update() + local Docs = require("lazy.docs") + Docs.plugins() + Docs.save({ keymaps = M.keymaps() }) + vim.cmd.checktime() +end + +M.update() + +return M diff --git a/lua/lazyvim/util.lua b/lua/lazyvim/util/init.lua similarity index 100% rename from lua/lazyvim/util.lua rename to lua/lazyvim/util/init.lua