which-key.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. local M = {}
  2. M.config = function()
  3. lvim.builtin.which_key = {
  4. ---@usage disable which-key completely [not recommended]
  5. active = true,
  6. on_config_done = nil,
  7. setup = {
  8. plugins = {
  9. marks = false, -- shows a list of your marks on ' and `
  10. registers = false, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
  11. -- the presets plugin, adds help for a bunch of default keybindings in Neovim
  12. -- No actual key bindings are created
  13. presets = {
  14. operators = false, -- adds help for operators like d, y, ...
  15. motions = false, -- adds help for motions
  16. text_objects = false, -- help for text objects triggered after entering an operator
  17. windows = false, -- default bindings on <c-w>
  18. nav = false, -- misc bindings to work with windows
  19. z = false, -- bindings for folds, spelling and others prefixed with z
  20. g = false, -- bindings for prefixed with g
  21. },
  22. spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints
  23. },
  24. icons = {
  25. breadcrumb = lvim.icons.ui.DoubleChevronRight, -- symbol used in the command line area that shows your active key combo
  26. separator = lvim.icons.ui.BoldArrowRight, -- symbol used between a key and it's label
  27. group = lvim.icons.ui.Plus, -- symbol prepended to a group
  28. },
  29. popup_mappings = {
  30. scroll_down = "<c-d>", -- binding to scroll down inside the popup
  31. scroll_up = "<c-u>", -- binding to scroll up inside the popup
  32. },
  33. window = {
  34. border = "single", -- none, single, double, shadow
  35. position = "bottom", -- bottom, top
  36. margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
  37. padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
  38. winblend = 0,
  39. },
  40. layout = {
  41. height = { min = 4, max = 25 }, -- min and max height of the columns
  42. width = { min = 20, max = 50 }, -- min and max width of the columns
  43. spacing = 3, -- spacing between columns
  44. align = "left", -- align columns left, center or right
  45. },
  46. hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
  47. ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
  48. show_help = true, -- show help message on the command line when the popup is visible
  49. triggers = "auto", -- automatically setup triggers
  50. -- triggers = {"<leader>"} -- or specify a list manually
  51. triggers_blacklist = {
  52. -- list of mode / prefixes that should never be hooked by WhichKey
  53. -- this is mostly relevant for key maps that start with a native binding
  54. -- most people should not need to change this
  55. i = { "j", "k" },
  56. v = { "j", "k" },
  57. },
  58. },
  59. opts = {
  60. mode = "n", -- NORMAL mode
  61. prefix = "<leader>",
  62. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  63. silent = true, -- use `silent` when creating keymaps
  64. noremap = true, -- use `noremap` when creating keymaps
  65. nowait = true, -- use `nowait` when creating keymaps
  66. },
  67. vopts = {
  68. mode = "v", -- VISUAL mode
  69. prefix = "<leader>",
  70. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  71. silent = true, -- use `silent` when creating keymaps
  72. noremap = true, -- use `noremap` when creating keymaps
  73. nowait = true, -- use `nowait` when creating keymaps
  74. },
  75. -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode.
  76. -- see https://neovim.io/doc/user/map.html#:map-cmd
  77. vmappings = {
  78. ["/"] = { "<Plug>(comment_toggle_linewise_visual)", "Comment toggle linewise (visual)" },
  79. },
  80. mappings = {
  81. [";"] = { "<cmd>Alpha<CR>", "Dashboard" },
  82. ["w"] = { "<cmd>w!<CR>", "Save" },
  83. ["q"] = { "<cmd>lua require('lvim.utils.functions').smart_quit()<CR>", "Quit" },
  84. ["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" },
  85. ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },
  86. ["f"] = { require("lvim.core.telescope.custom-finders").find_project_files, "Find File" },
  87. ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
  88. b = {
  89. name = "Buffers",
  90. j = { "<cmd>BufferLinePick<cr>", "Jump" },
  91. f = { "<cmd>Telescope buffers<cr>", "Find" },
  92. b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" },
  93. n = { "<cmd>BufferLineCycleNext<cr>", "Next" },
  94. -- w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, -- TODO: implement this for bufferline
  95. e = {
  96. "<cmd>BufferLinePickClose<cr>",
  97. "Pick which buffer to close",
  98. },
  99. h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" },
  100. l = {
  101. "<cmd>BufferLineCloseRight<cr>",
  102. "Close all to the right",
  103. },
  104. D = {
  105. "<cmd>BufferLineSortByDirectory<cr>",
  106. "Sort by directory",
  107. },
  108. L = {
  109. "<cmd>BufferLineSortByExtension<cr>",
  110. "Sort by language",
  111. },
  112. },
  113. p = {
  114. name = "Packer",
  115. c = { "<cmd>PackerCompile<cr>", "Compile" },
  116. i = { "<cmd>PackerInstall<cr>", "Install" },
  117. r = { "<cmd>lua require('lvim.plugin-loader').recompile()<cr>", "Re-compile" },
  118. s = { "<cmd>PackerSync<cr>", "Sync" },
  119. S = { "<cmd>PackerStatus<cr>", "Status" },
  120. u = { "<cmd>PackerUpdate<cr>", "Update" },
  121. },
  122. -- " Available Debug Adapters:
  123. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  124. -- " Adapter configuration and installation instructions:
  125. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  126. -- " Debug Adapter protocol:
  127. -- " https://microsoft.github.io/debug-adapter-protocol/
  128. -- " Debugging
  129. g = {
  130. name = "Git",
  131. g = { "<cmd>lua require 'lvim.core.terminal'.lazygit_toggle()<cr>", "Lazygit" },
  132. j = { "<cmd>lua require 'gitsigns'.next_hunk({navigation_message = false})<cr>", "Next Hunk" },
  133. k = { "<cmd>lua require 'gitsigns'.prev_hunk({navigation_message = false})<cr>", "Prev Hunk" },
  134. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  135. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  136. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  137. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  138. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  139. u = {
  140. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  141. "Undo Stage Hunk",
  142. },
  143. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  144. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  145. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  146. C = {
  147. "<cmd>Telescope git_bcommits<cr>",
  148. "Checkout commit(for current file)",
  149. },
  150. d = {
  151. "<cmd>Gitsigns diffthis HEAD<cr>",
  152. "Git Diff",
  153. },
  154. },
  155. l = {
  156. name = "LSP",
  157. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  158. d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" },
  159. w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
  160. f = { require("lvim.lsp.utils").format, "Format" },
  161. i = { "<cmd>LspInfo<cr>", "Info" },
  162. I = { "<cmd>Mason<cr>", "Mason Info" },
  163. j = {
  164. vim.diagnostic.goto_next,
  165. "Next Diagnostic",
  166. },
  167. k = {
  168. vim.diagnostic.goto_prev,
  169. "Prev Diagnostic",
  170. },
  171. l = { vim.lsp.codelens.run, "CodeLens Action" },
  172. q = { vim.diagnostic.setloclist, "Quickfix" },
  173. r = { vim.lsp.buf.rename, "Rename" },
  174. s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
  175. S = {
  176. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  177. "Workspace Symbols",
  178. },
  179. e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" },
  180. },
  181. L = {
  182. name = "+LunarVim",
  183. c = {
  184. "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",
  185. "Edit config.lua",
  186. },
  187. f = {
  188. "<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>",
  189. "Find LunarVim files",
  190. },
  191. g = {
  192. "<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>",
  193. "Grep LunarVim files",
  194. },
  195. k = { "<cmd>Telescope keymaps<cr>", "View LunarVim's keymappings" },
  196. i = {
  197. "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>",
  198. "Toggle LunarVim Info",
  199. },
  200. I = {
  201. "<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>",
  202. "View LunarVim's changelog",
  203. },
  204. l = {
  205. name = "+logs",
  206. d = {
  207. "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>",
  208. "view default log",
  209. },
  210. D = {
  211. "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>",
  212. "Open the default logfile",
  213. },
  214. l = {
  215. "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>",
  216. "view lsp log",
  217. },
  218. L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" },
  219. n = {
  220. "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
  221. "view neovim log",
  222. },
  223. N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
  224. p = {
  225. "<cmd>lua require('lvim.core.terminal').toggle_log_view(get_cache_dir() .. '/packer.nvim.log')<cr>",
  226. "view packer log",
  227. },
  228. P = { "<cmd>edit $LUNARVIM_CACHE_DIR/packer.nvim.log<cr>", "Open the Packer logfile" },
  229. },
  230. n = { "<cmd>Telescope notify<cr>", "View Notifications" },
  231. r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
  232. u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
  233. },
  234. s = {
  235. name = "Search",
  236. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  237. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  238. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  239. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  240. H = { "<cmd>Telescope highlights<cr>", "Find highlight groups" },
  241. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  242. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  243. R = { "<cmd>Telescope registers<cr>", "Registers" },
  244. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  245. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  246. C = { "<cmd>Telescope commands<cr>", "Commands" },
  247. p = {
  248. "<cmd>lua require('telescope.builtin').colorscheme({enable_preview = true})<cr>",
  249. "Colorscheme with Preview",
  250. },
  251. },
  252. T = {
  253. name = "Treesitter",
  254. i = { ":TSConfigInfo<cr>", "Info" },
  255. },
  256. },
  257. }
  258. end
  259. M.setup = function()
  260. local which_key = require "which-key"
  261. which_key.setup(lvim.builtin.which_key.setup)
  262. local opts = lvim.builtin.which_key.opts
  263. local vopts = lvim.builtin.which_key.vopts
  264. local mappings = lvim.builtin.which_key.mappings
  265. local vmappings = lvim.builtin.which_key.vmappings
  266. which_key.register(mappings, opts)
  267. which_key.register(vmappings, vopts)
  268. if lvim.builtin.which_key.on_config_done then
  269. lvim.builtin.which_key.on_config_done(which_key)
  270. end
  271. end
  272. return M