From 69296d8f4690886e067f8e17a320ce9278dc51da Mon Sep 17 00:00:00 2001 From: fabmorais Date: Fri, 8 Nov 2024 18:20:51 +0100 Subject: [PATCH] Refactor which-key --- lazy-lock.json | 13 +- lua/lazy-config/init.lua | 18 +- lua/which-config/init.lua | 349 +++++++++++++++++++++++++------------- 3 files changed, 252 insertions(+), 128 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index b5586cc..6440624 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,5 +1,4 @@ { - "CopilotChat.nvim": { "branch": "canary", "commit": "18d51754e9dc87d6b85f1e331c1fca0825384517" }, "LuaSnip": { "branch": "master", "commit": "2737edc9e674e537dc0a97e3405658d57d2d31ed" }, "auto-session": { "branch": "main", "commit": "542d338ec5ee027638c8e076110b188a465b45d2" }, "barbar.nvim": { "branch": "master", "commit": "7c28de8c22f4c00ed43a78ae16c13dd6a248fe1a" }, @@ -7,7 +6,6 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "codeium.vim": { "branch": "main", "commit": "8c01979323b2b480c8bf160d3ff85bd1668baa49" }, - "copilot.vim": { "branch": "release", "commit": "87038123804796ca7af20d1b71c3428d858a9124" }, "dashboard-nvim": { "branch": "master", "commit": "ae309606940d26d8c9df8b048a6e136b6bbec478" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "dracula.nvim": { "branch": "main", "commit": "94fa7885a06a67f0a8bfa03e064619d05d1ba496" }, @@ -18,7 +16,7 @@ "lazy.nvim": { "branch": "main", "commit": "b1134ab82ee4279e31f7ddf7e34b2a99eb9b7bc9" }, "lspkind-nvim": { "branch": "master", "commit": "a700f1436d4a938b1a1a93c9962dc796afbaef4d" }, "lspsaga.nvim": { "branch": "main", "commit": "d027f8b9c7c55e26cf4030c8657a2fc8222ed762" }, - "lualine.nvim": { "branch": "master", "commit": "640260d7c2d98779cab89b1e7088ab14ea354a02" }, + "lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "mini.icons": { "branch": "main", "commit": "a2742459f0ee32806c2438ca06b4d8b331f3f4d4" }, @@ -32,12 +30,12 @@ "nvim-dap": { "branch": "master", "commit": "8517126e9323e346f6a99b3b594c5a940b914dcd" }, "nvim-dap-ui": { "branch": "master", "commit": "ffa89839f97bad360e78428d5c740fdad9a0ff02" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "76d80c3d171224315b61c006502a1e30c213a9ab" }, - "nvim-lspconfig": { "branch": "master", "commit": "52302604e3c667cfdf33aadf89088e96eb3c5da3" }, + "nvim-lspconfig": { "branch": "master", "commit": "d01864641c6e43c681c3e9f6cf4745c75fdd9dcc" }, "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, "nvim-notify": { "branch": "master", "commit": "fbef5d32be8466dd76544a257d3f3dce20082a07" }, "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" }, "nvim-tree.lua": { "branch": "master", "commit": "610a1c189bdb2b9b936169b2ea9d1838f971fa2b" }, - "nvim-treesitter": { "branch": "master", "commit": "4b9a83f6017ee5edea85722cbfda1b3058a82e69" }, + "nvim-treesitter": { "branch": "master", "commit": "425b58968340bd5b4621c2a0d626c73556516d3d" }, "nvim-treesitter-refactor": { "branch": "master", "commit": "d8b74fa87afc6a1e97b18da23e762efb032dc270" }, "nvim-ts-rainbow": { "branch": "master", "commit": "ef95c15a935f97c65a80e48e12fe72d49aacf9b9" }, "nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" }, @@ -48,10 +46,11 @@ "synthwave": { "branch": "main", "commit": "d638ea221b4c6636978f49c1987d10ff2733c23d" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope.nvim": { "branch": "master", "commit": "85922dde3767e01d42a08e750a773effbffaea3e" }, - "tint.nvim": { "branch": "master", "commit": "02bd0527a315a80e4e25bb2dd7b6994fb0daae01" }, + "tint.nvim": { "branch": "master", "commit": "586e87f00c8b0f5e857cefe10839e41f3e8c6d01" }, "toggleterm.nvim": { "branch": "main", "commit": "5969229c0352ff1ed7f6e24aba9c6554e1842939" }, "tokyonight.nvim": { "branch": "main", "commit": "ce91ba480070c95f40753e4663e32b4632ac6db3" }, "undotree": { "branch": "master", "commit": "78b5241191852ffa9bb5da5ff2ee033160798c3b" }, - "which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" }, + "vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" }, + "which-key.nvim": { "branch": "main", "commit": "68e37e12913a66b60073906f5d3f14dee0de19f2" }, "wilder.nvim": { "branch": "master", "commit": "679f348dc90d80ff9ba0e7c470c40a4d038dcecf" } } diff --git a/lua/lazy-config/init.lua b/lua/lazy-config/init.lua index 8caaa60..4f3e5e2 100644 --- a/lua/lazy-config/init.lua +++ b/lua/lazy-config/init.lua @@ -27,8 +27,23 @@ local plugins = { dependencies = { "nvim-lua/plenary.nvim" }, }, { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, - { "folke/which-key.nvim" }, + { + "folke/which-key.nvim", + event = "VeryLazy", + keys = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Local Keymaps (which-key)", + }, + }, + }, { "akinsho/toggleterm.nvim" }, + + --> Git + { "tpope/vim-fugitive" }, { "lewis6991/gitsigns.nvim", dependencies = { "nvim-lua/plenary.nvim" }, @@ -36,6 +51,7 @@ local plugins = { require("gitsigns").setup({ current_line_blame = true }) end, }, + { "levouh/tint.nvim" }, { "terrortylor/nvim-comment" }, { "norcalli/nvim-colorizer.lua" }, diff --git a/lua/which-config/init.lua b/lua/which-config/init.lua index 53d2560..f83cfdb 100644 --- a/lua/which-config/init.lua +++ b/lua/which-config/init.lua @@ -1,20 +1,4 @@ local wk = require("which-key") -wk.setup({ - plugins = { - marks = false, - registers = false, - spelling = { enabled = false, suggestions = 20 }, - presets = { - operators = false, - motions = false, - text_objects = false, - windows = false, - nav = false, - z = false, - g = false, - }, - }, -}) local Terminal = require("toggleterm.terminal").Terminal @@ -28,108 +12,233 @@ local toggle_lazygit = function() return lazygit:toggle() end -local mappings = { - ["/"] = { ":CommentToggle", "Toggle Comment" }, - c = { - name = "Dashboard", - c = { ":Dashboard", "Open dashboard" }, - }, - q = { ":q", "Quit" }, - Q = { ":wq", "Save & Quit" }, - w = { ":w", "Save" }, - x = { ":bdelete", "Close" }, - E = { ":e ~/.config/nvim/init.lua", "Edit config" }, - f = { - name = "Telescope", - f = { ":Telescope find_files", "Telescope find files" }, - g = { ":Telescope live_grep", "Telescope live grep" }, - r = { ":Telescope grep_string", "Telescope grep string" }, - o = { ":Telescope oldfiles", "Telescope find old files" }, - h = { ":Telescope help_tags", "Telescope help page" }, - b = { ":Telescope buffers", "Telescope find buffers" }, - m = { ":Telescope marks", "telescope find marks" }, - z = { ":Telescope current_buffer_fuzzy_find", "telescope find in current buffer" }, - c = { ":Telescope git_commits", "telescope git commits" }, - s = { ":Telescope git_status", "telescope git status" }, - }, - g = { - name = "ChatGPT", - c = { "ChatGPT", "ChatGPT" }, - b = { "ChatGPTCompleteCode", "ChatGPTCompleteCode" }, - e = { "ChatGPTEditWithInstruction", "Edit with instruction", mode = { "n", "v" } }, - g = { "ChatGPTRun grammar_correction", "Grammar Correction", mode = { "n", "v" } }, - t = { "ChatGPTRun translate", "Translate", mode = { "n", "v" } }, - k = { "ChatGPTRun keywords", "Keywords", mode = { "n", "v" } }, - d = { "ChatGPTRun docstring", "Docstring", mode = { "n", "v" } }, - a = { "ChatGPTRun add_tests", "Add Tests", mode = { "n", "v" } }, - o = { "ChatGPTRun optimize_code", "Optimize Code", mode = { "n", "v" } }, - s = { "ChatGPTRun summarize", "Summarize", mode = { "n", "v" } }, - f = { "ChatGPTRun fix_bugs", "Fix Bugs", mode = { "n", "v" } }, - x = { "ChatGPTRun explain_code", "Explain Code", mode = { "n", "v" } }, - r = { "ChatGPTRun roxygen_edit", "Roxygen Edit", mode = { "n", "v" } }, - l = { "ChatGPTRun code_readability_analysis", "Code Readability Analysis", mode = { "n", "v" } }, - }, - b = { - name = "Telescope Bookmarks", - m = { ":Telescope marks", "Bookmarks" }, - }, - t = { - name = "Terminal", - t = { ":ToggleTerm", "Split Below" }, - f = { toggle_float, "Floating Terminal" }, - l = { toggle_lazygit, "LazyGit" }, - }, - l = { - name = "LSP", - i = { ":LspInfo", "Connected Language Servers" }, - k = { "lua vim.lsp.buf.signature_help()", "Signature Help" }, - K = { "Lspsaga hover_doc", "Hover Commands" }, - w = { "lua vim.lsp.buf.add_workspace_folder()", "Add Workspace Folder" }, - W = { "lua vim.lsp.buf.remove_workspace_folder()", "Remove Workspace Folder" }, - l = { - "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", - "List Workspace Folders", - }, - t = { "lua vim.lsp.buf.type_definition()", "Type Definition" }, - d = { "lua vim.lsp.buf.definition()", "Go To Definition" }, - D = { "lua vim.lsp.buf.declaration()", "Go To Declaration" }, - r = { "lua vim.lsp.buf.references()", "References" }, - R = { "Lspsaga rename", "Rename" }, - a = { "Lspsaga code_action", "Code Action" }, - e = { "Lspsaga show_line_diagnostics", "Show Line Diagnostics" }, - n = { "Lspsaga diagnostic_jump_next", "Go To Next Diagnostic" }, - N = { "Lspsaga diagnostic_jump_prev", "Go To Previous Diagnostic" }, - }, - p = { - name = "Packer", - r = { ":PackerClean", "Remove Unused Plugins" }, - c = { ":PackerCompile profile=true", "Recompile Plugins" }, - i = { ":PackerInstall", "Install Plugins" }, - p = { ":PackerProfile", "Packer Profile" }, - s = { ":PackerSync", "Sync Plugins" }, - S = { ":PackerStatus", "Packer Status" }, - u = { ":PackerUpdate", "Update Plugins" }, - }, - -- debugger mappings -- - d = { - name = "Debugger", - c = { "lua require'dap'.continue()", "Continue" }, - o = { "lua require'dap'.step_over()", "Step Over" }, - i = { "lua require'dap'.step_into()", "Step Into" }, - O = { "lua require'dap'.step_out()", "Step Out" }, - b = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, - s = { - "lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: '))", - "Set Breakpoint condition", - }, - B = { - "lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: '))", - "Set Breakpoint log message", - }, - n = { "lua require'dap'.repl.open()", "Open" }, - l = { "lua require'dap'.run_last()", "Run Last" }, - }, -} +wk.add({ + -- General + { + mode = { "n", "v" }, -- NORMAL and VISUAL mode + { "q", "q", desc = "Quit" }, + { "w", "w", desc = "Write" }, + }, + -- Dashboard + { "d", group = "Dashboard" }, -- group + { + "db", + ":Dashboard", + desc = "Open dashboard", + mode = "n", + }, + -- Terminal + { "t", group = "Terminal" }, -- group + { + "tt", + "ToggleTerm direction=horizontal", + desc = "Split Below", + mode = "n", + }, + { + "tf", + toggle_float, + desc = "Floating Terminal", + mode = "n", + }, + { + "tl", + toggle_lazygit, + desc = "LazyGit", + mode = "n", + }, + -- Close Buffer + { + "x", + "bdelete", + desc = "Close window", + mode = "n", + }, + -- Telescope + { "f", group = "File" }, -- group + { + "ff", + "Telescope find_files", + desc = "Find File", + mode = "n", + }, + { + "fg", + "Telescope live_grep", + desc = "Live Grep", + mode = "n", + }, + { + "fb", + "Telescope buffers", + desc = "Buffers", + mode = "n", + }, + { + "fh", + "Telescope help_tags", + desc = "Help", + mode = "n", + }, + { + "fk", + "Telescope keymaps", + desc = "Keymaps", + mode = "n", + }, + { + "fo", + "Telescope oldfiles", + desc = "Find Recent", + mode = "n", + }, + { + "fd", + "Telescope diagnostics", + desc = "Diagnostics", + mode = "n", + }, + { + "fm", + "Telescope marks", + desc = "Marks", + mode = "n", + }, + { + "fr", + "Telescope grep_string", + desc = "Find Word", + mode = "n", + }, + + -- LSP + { "l", group = "Lsp" }, -- group + { + "li", + "LspInfo", + desc = "Connected Language Servers", + mode = "n", + }, + { + "lR", + "Lspsaga rename", + desc = "Rename", + mode = "n", + }, + { + "la", + "Lspsaga code_action", + desc = "Code Action", + mode = "n", + }, + { + "ln", + "Lspsaga diagnostic_jump_next", + desc = "Go To Next Diagnostic", + mode = "n", + }, + { + "lN", + "Lspsaga diagnostic_jump_prev", + desc = "Go To Previous Diagnostic", + mode = "n", + }, + { + "lr", + "lua vim.lsp.buf.references()", + desc = "References", + mode = "n", + }, + { + "le", + "Lspsaga show_line_diagnostics", + desc = "Show Line Diagnostics", + mode = "n", + }, + { + "lt", + "lua vim.lsp.buf.type_definition()", + desc = "Type Definition", + mode = "n", + }, + { + "ld", + "lua vim.lsp.buf.definition()", + desc = "Go To Definition", + mode = "n", + }, + { + "lD", + "lua vim.lsp.buf.declaration()", + desc = "Go To Declaration", + mode = "n", + }, + { + "lk", + "lua vim.lsp.buf.signature_help()", + desc = "Signature Help", + mode = "n", + }, + { + "lh", + "lua vim.lsp.buf.hover()", + desc = "Hover", + mode = "n", + }, + { + "ll", + "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", + desc = "List Workspace Folders", + mode = "n", + }, + { + "lw", + "lua vim.lsp.buf.add_workspace_folder()", + desc = "Add Workspace Folder", + mode = "n", + }, + { + "lW", + "lua vim.lsp.buf.remove_workspace_folder()", + desc = "Remove Workspace Folder", + mode = "n", + }, -local opts = { prefix = "" } -wk.register(mappings, opts) + -- Git + { "r", group = "Git" }, -- group + { + "rc", + "Telescope git_commits", + desc = "Git commits", + mode = "n", + }, + { + "rz", + "Telescope git_status", + desc = "Git status", + mode = "n", + }, + { + "rs", + "lua require 'gitsigns'.stage_buffer()", + desc = "Stage Buffer", + mode = "n", + }, + { "rg", "lua require 'gitsigns'.status()", desc = "Status", mode = "n" }, + { + "rb", + "lua require 'gitsigns'.blame_line()", + desc = "Blame Line", + mode = "n", + }, + { "rt", "lua require 'gitsigns'.toggle_current_line_blame()", desc = "Toggle Blame" }, + { "rr", "lua require 'gitsigns'.reset_buffer()", desc = "Reset Buffer" }, + { "ru", "lua require 'gitsigns'.undo_stage_hunk()", desc = "Undo Stage Hunk" }, + { "rp", "lua require 'gitsigns'.preview_hunk()", desc = "Preview Hunk" }, + { "rd", "lua require 'gitsigns'.diffthis()", desc = "Diff This" }, + { "rD", "lua require 'gitsigns'.diffthis('~')", desc = "Diff This ~" }, + { "rh", "lua require 'gitsigns'.reset_hunk()", desc = "Reset Hunk" }, + { "rH", "lua require 'gitsigns'.reset_buffer()", desc = "Reset Buffer" }, + { "rS", "lua require 'gitsigns'.stage_hunk()", desc = "Stage Hunk" }, + { "rk", "lua require 'gitsigns'.toggle_deleted()", desc = "Toggle Deleted" }, +})