which-key.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 = true, -- shows a list of your marks on ' and `
  10. registers = true, -- 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 = true, -- misc bindings to work with windows
  19. z = true, -- bindings for folds, spelling and others prefixed with z
  20. g = true, -- bindings for prefixed with g
  21. },
  22. spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints
  23. },
  24. icons = {
  25. breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
  26. separator = "➜", -- symbol used between a key and it's label
  27. group = "+", -- 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. ["/"] = { "<ESC><CMD>lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<CR>", "Comment" },
  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. ["/"] = { "<cmd>lua require('Comment.api').toggle_current_linewise()<CR>", "Comment" },
  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. -- w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, -- TODO: implement this for bufferline
  94. e = {
  95. "<cmd>BufferLinePickClose<cr>",
  96. "Pick which buffer to close",
  97. },
  98. h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" },
  99. l = {
  100. "<cmd>BufferLineCloseRight<cr>",
  101. "Close all to the right",
  102. },
  103. D = {
  104. "<cmd>BufferLineSortByDirectory<cr>",
  105. "Sort by directory",
  106. },
  107. L = {
  108. "<cmd>BufferLineSortByExtension<cr>",
  109. "Sort by language",
  110. },
  111. },
  112. p = {
  113. name = "Packer",
  114. c = { "<cmd>PackerCompile<cr>", "Compile" },
  115. i = { "<cmd>PackerInstall<cr>", "Install" },
  116. r = { "<cmd>lua require('lvim.plugin-loader').recompile()<cr>", "Re-compile" },
  117. s = { "<cmd>PackerSync<cr>", "Sync" },
  118. S = { "<cmd>PackerStatus<cr>", "Status" },
  119. u = { "<cmd>PackerUpdate<cr>", "Update" },
  120. },
  121. -- " Available Debug Adapters:
  122. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  123. -- " Adapter configuration and installation instructions:
  124. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  125. -- " Debug Adapter protocol:
  126. -- " https://microsoft.github.io/debug-adapter-protocol/
  127. -- " Debugging
  128. g = {
  129. name = "Git",
  130. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  131. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  132. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  133. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  134. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  135. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  136. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  137. u = {
  138. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  139. "Undo Stage Hunk",
  140. },
  141. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  142. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  143. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  144. C = {
  145. "<cmd>Telescope git_bcommits<cr>",
  146. "Checkout commit(for current file)",
  147. },
  148. d = {
  149. "<cmd>Gitsigns diffthis HEAD<cr>",
  150. "Git Diff",
  151. },
  152. },
  153. l = {
  154. name = "LSP",
  155. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  156. d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" },
  157. w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
  158. f = { require("lvim.lsp.utils").format, "Format" },
  159. i = { "<cmd>LspInfo<cr>", "Info" },
  160. I = { "<cmd>LspInstallInfo<cr>", "Installer Info" },
  161. j = {
  162. vim.diagnostic.goto_next,
  163. "Next Diagnostic",
  164. },
  165. k = {
  166. vim.diagnostic.goto_prev,
  167. "Prev Diagnostic",
  168. },
  169. l = { vim.lsp.codelens.run, "CodeLens Action" },
  170. p = {
  171. name = "Peek",
  172. d = { "<cmd>lua require('lvim.lsp.peek').Peek('definition')<cr>", "Definition" },
  173. t = { "<cmd>lua require('lvim.lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" },
  174. i = { "<cmd>lua require('lvim.lsp.peek').Peek('implementation')<cr>", "Implementation" },
  175. },
  176. q = { vim.diagnostic.setloclist, "Quickfix" },
  177. r = { vim.lsp.buf.rename, "Rename" },
  178. s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
  179. S = {
  180. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  181. "Workspace Symbols",
  182. },
  183. e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" },
  184. },
  185. L = {
  186. name = "+LunarVim",
  187. c = {
  188. "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",
  189. "Edit config.lua",
  190. },
  191. f = {
  192. "<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>",
  193. "Find LunarVim files",
  194. },
  195. g = {
  196. "<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>",
  197. "Grep LunarVim files",
  198. },
  199. k = { "<cmd>Telescope keymaps<cr>", "View LunarVim's keymappings" },
  200. i = {
  201. "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>",
  202. "Toggle LunarVim Info",
  203. },
  204. I = {
  205. "<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>",
  206. "View LunarVim's changelog",
  207. },
  208. l = {
  209. name = "+logs",
  210. d = {
  211. "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>",
  212. "view default log",
  213. },
  214. D = {
  215. "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>",
  216. "Open the default logfile",
  217. },
  218. l = {
  219. "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>",
  220. "view lsp log",
  221. },
  222. L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" },
  223. n = {
  224. "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
  225. "view neovim log",
  226. },
  227. N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
  228. p = {
  229. "<cmd>lua require('lvim.core.terminal').toggle_log_view(get_cache_dir() .. '/packer.nvim.log')<cr>",
  230. "view packer log",
  231. },
  232. P = { "<cmd>edit $LUNARVIM_CACHE_DIR/packer.nvim.log<cr>", "Open the Packer logfile" },
  233. },
  234. n = { "<cmd>Telescope notify<cr>", "View Notifications" },
  235. r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
  236. u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
  237. },
  238. s = {
  239. name = "Search",
  240. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  241. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  242. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  243. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  244. H = { "<cmd>Telescope highlights<cr>", "Find highlight groups" },
  245. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  246. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  247. R = { "<cmd>Telescope registers<cr>", "Registers" },
  248. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  249. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  250. C = { "<cmd>Telescope commands<cr>", "Commands" },
  251. p = {
  252. "<cmd>lua require('telescope.builtin.internal').colorscheme({enable_preview = true})<cr>",
  253. "Colorscheme with Preview",
  254. },
  255. },
  256. T = {
  257. name = "Treesitter",
  258. i = { ":TSConfigInfo<cr>", "Info" },
  259. },
  260. },
  261. }
  262. end
  263. M.setup = function()
  264. local which_key = require "which-key"
  265. which_key.setup(lvim.builtin.which_key.setup)
  266. local opts = lvim.builtin.which_key.opts
  267. local vopts = lvim.builtin.which_key.vopts
  268. local mappings = lvim.builtin.which_key.mappings
  269. local vmappings = lvim.builtin.which_key.vmappings
  270. which_key.register(mappings, opts)
  271. which_key.register(vmappings, vopts)
  272. if lvim.builtin.which_key.on_config_done then
  273. lvim.builtin.which_key.on_config_done(which_key)
  274. end
  275. end
  276. return M