which-key.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. [";"] = { "<cmd>Dashboard<CR>", "Dashboard" },
  71. p = {
  72. name = "Packer",
  73. c = { "<cmd>PackerCompile<cr>", "Compile" },
  74. i = { "<cmd>PackerInstall<cr>", "Install" },
  75. r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" },
  76. s = { "<cmd>PackerSync<cr>", "Sync" },
  77. u = { "<cmd>PackerUpdate<cr>", "Update" },
  78. },
  79. -- " Available Debug Adapters:
  80. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  81. -- " Adapter configuration and installation instructions:
  82. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  83. -- " Debug Adapter protocol:
  84. -- " https://microsoft.github.io/debug-adapter-protocol/
  85. -- " Debugging
  86. g = {
  87. name = "Git",
  88. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  89. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  90. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  91. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  92. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  93. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  94. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  95. u = {
  96. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  97. "Undo Stage Hunk",
  98. },
  99. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  100. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  101. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  102. C = {
  103. "<cmd>Telescope git_bcommits<cr>",
  104. "Checkout commit(for current file)",
  105. },
  106. },
  107. l = {
  108. name = "LSP",
  109. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  110. d = {
  111. "<cmd>Telescope lsp_document_diagnostics<cr>",
  112. "Document Diagnostics",
  113. },
  114. w = {
  115. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  116. "Workspace Diagnostics",
  117. },
  118. f = { "<cmd>silent FormatWrite<cr>", "Format" },
  119. i = { "<cmd>LspInfo<cr>", "Info" },
  120. j = {
  121. "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>",
  122. "Next Diagnostic",
  123. },
  124. k = {
  125. "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>",
  126. "Prev Diagnostic",
  127. },
  128. q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
  129. r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
  130. s = { "<cmd> Telescope lsp_document_symbols<cr>", "Document Symbols" },
  131. S = {
  132. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  133. "Workspace Symbols",
  134. },
  135. },
  136. s = {
  137. name = "Search",
  138. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  139. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  140. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  141. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  142. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  143. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  144. R = { "<cmd>Telescope registers<cr>", "Registers" },
  145. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  146. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  147. C = { "<cmd>Telescope commands<cr>", "Commands" },
  148. },
  149. T = {
  150. name = "Treesitter",
  151. i = { ":TSConfigInfo<cr>", "Info" },
  152. },
  153. },
  154. }
  155. end
  156. M.setup = function()
  157. -- if not package.loaded['which-key'] then
  158. -- return
  159. -- end
  160. local status_ok, which_key = pcall(require, "which-key")
  161. if not status_ok then
  162. return
  163. end
  164. which_key.setup(O.plugin.which_key.setup)
  165. local opts = O.plugin.which_key.opts
  166. local vopts = O.plugin.which_key.vopts
  167. local mappings = O.plugin.which_key.mappings
  168. local vmappings = O.plugin.which_key.vmappings
  169. -- if O.plugin.ts_playground.active then
  170. -- vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true })
  171. -- mappings[""] = "Highlight Capture"
  172. -- end
  173. if O.plugin.zen.active then
  174. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true })
  175. mappings["z"] = "Zen"
  176. end
  177. for k, v in pairs(O.user_which_key) do
  178. mappings[k] = v
  179. end
  180. local wk = require "which-key"
  181. wk.register(mappings, opts)
  182. wk.register(vmappings, vopts)
  183. end
  184. return M