which-key.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. local M = {}
  2. M.config = function()
  3. O.plugin.which_key = {
  4. active = false,
  5. setup = {
  6. plugins = {
  7. marks = true, -- shows a list of your marks on ' and `
  8. registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
  9. -- the presets plugin, adds help for a bunch of default keybindings in Neovim
  10. -- No actual key bindings are created
  11. presets = {
  12. operators = false, -- adds help for operators like d, y, ...
  13. motions = false, -- adds help for motions
  14. text_objects = false, -- help for text objects triggered after entering an operator
  15. windows = true, -- default bindings on <c-w>
  16. nav = true, -- misc bindings to work with windows
  17. z = true, -- bindings for folds, spelling and others prefixed with z
  18. g = true, -- bindings for prefixed with g
  19. },
  20. spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints
  21. },
  22. icons = {
  23. breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
  24. separator = "➜", -- symbol used between a key and it's label
  25. group = "+", -- symbol prepended to a group
  26. },
  27. window = {
  28. border = "single", -- none, single, double, shadow
  29. position = "bottom", -- bottom, top
  30. margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
  31. padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
  32. },
  33. layout = {
  34. height = { min = 4, max = 25 }, -- min and max height of the columns
  35. width = { min = 20, max = 50 }, -- min and max width of the columns
  36. spacing = 3, -- spacing between columns
  37. },
  38. hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
  39. show_help = true, -- show help message on the command line when the popup is visible
  40. },
  41. opts = {
  42. mode = "n", -- NORMAL mode
  43. prefix = "<leader>",
  44. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  45. silent = true, -- use `silent` when creating keymaps
  46. noremap = true, -- use `noremap` when creating keymaps
  47. nowait = true, -- use `nowait` when creating keymaps
  48. },
  49. vopts = {
  50. mode = "v", -- VISUAL mode
  51. prefix = "<leader>",
  52. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  53. silent = true, -- use `silent` when creating keymaps
  54. noremap = true, -- use `noremap` when creating keymaps
  55. nowait = true, -- use `nowait` when creating keymaps
  56. },
  57. -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode.
  58. -- see https://neovim.io/doc/user/map.html#:map-cmd
  59. vmappings = {
  60. ["/"] = { ":CommentToggle<CR>", "Comment" },
  61. },
  62. mappings = {
  63. ["w"] = { "<cmd>w!<CR>", "Save" },
  64. ["q"] = { "<cmd>q!<CR>", "Quit" },
  65. ["/"] = { "<cmd>CommentToggle<CR>", "Comment" },
  66. ["c"] = { "<cmd>BufferClose<CR>", "Close Buffer" },
  67. ["e"] = { "<cmd>lua require'core.nvimtree'.toggle_tree()<CR>", "Explorer" },
  68. ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" },
  69. ["h"] = { '<cmd>let @/=""<CR>', "No Highlight" },
  70. p = {
  71. name = "Packer",
  72. c = { "<cmd>PackerCompile<cr>", "Compile" },
  73. i = { "<cmd>PackerInstall<cr>", "Install" },
  74. r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" },
  75. s = { "<cmd>PackerSync<cr>", "Sync" },
  76. u = { "<cmd>PackerUpdate<cr>", "Update" },
  77. },
  78. -- " Available Debug Adapters:
  79. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  80. -- " Adapter configuration and installation instructions:
  81. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  82. -- " Debug Adapter protocol:
  83. -- " https://microsoft.github.io/debug-adapter-protocol/
  84. -- " Debugging
  85. g = {
  86. name = "Git",
  87. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  88. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  89. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  90. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  91. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  92. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  93. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  94. u = {
  95. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  96. "Undo Stage Hunk",
  97. },
  98. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  99. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  100. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  101. C = {
  102. "<cmd>Telescope git_bcommits<cr>",
  103. "Checkout commit(for current file)",
  104. },
  105. },
  106. l = {
  107. name = "LSP",
  108. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  109. d = {
  110. "<cmd>Telescope lsp_document_diagnostics<cr>",
  111. "Document Diagnostics",
  112. },
  113. w = {
  114. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  115. "Workspace Diagnostics",
  116. },
  117. f = { "<cmd>silent FormatWrite<cr>", "Format" },
  118. i = { "<cmd>LspInfo<cr>", "Info" },
  119. j = {
  120. "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>",
  121. "Next Diagnostic",
  122. },
  123. k = {
  124. "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>",
  125. "Prev Diagnostic",
  126. },
  127. q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
  128. r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
  129. s = { "<cmd> Telescope lsp_document_symbols<cr>", "Document Symbols" },
  130. S = {
  131. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  132. "Workspace Symbols",
  133. },
  134. },
  135. s = {
  136. name = "Search",
  137. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  138. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  139. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  140. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  141. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  142. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  143. R = { "<cmd>Telescope registers<cr>", "Registers" },
  144. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  145. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  146. C = { "<cmd>Telescope commands<cr>", "Commands" },
  147. },
  148. T = {
  149. name = "Treesitter",
  150. i = { ":TSConfigInfo<cr>", "Info" },
  151. },
  152. },
  153. }
  154. end
  155. M.setup = function()
  156. -- if not package.loaded['which-key'] then
  157. -- return
  158. -- end
  159. local status_ok, which_key = pcall(require, "which-key")
  160. if not status_ok then
  161. return
  162. end
  163. which_key.setup(O.plugin.which_key.setup)
  164. local opts = O.plugin.which_key.opts
  165. local vopts = O.plugin.which_key.vopts
  166. local mappings = O.plugin.which_key.mappings
  167. local vmappings = O.plugin.which_key.vmappings
  168. -- if O.plugin.ts_playground.active then
  169. -- vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true })
  170. -- mappings[""] = "Highlight Capture"
  171. -- end
  172. if O.plugin.zen.active then
  173. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true })
  174. mappings["z"] = "Zen"
  175. end
  176. local wk = require "which-key"
  177. wk.register(mappings, opts)
  178. wk.register(vmappings, vopts)
  179. wk.register(O.user_which_key, opts)
  180. end
  181. return M