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. 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. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  132. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  133. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  134. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  135. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  136. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  137. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  138. u = {
  139. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  140. "Undo Stage Hunk",
  141. },
  142. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  143. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  144. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  145. C = {
  146. "<cmd>Telescope git_bcommits<cr>",
  147. "Checkout commit(for current file)",
  148. },
  149. d = {
  150. "<cmd>Gitsigns diffthis HEAD<cr>",
  151. "Git Diff",
  152. },
  153. },
  154. l = {
  155. name = "LSP",
  156. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  157. d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" },
  158. w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
  159. f = { require("lvim.lsp.utils").format, "Format" },
  160. i = { "<cmd>LspInfo<cr>", "Info" },
  161. I = { "<cmd>Mason<cr>", "Mason Info" },
  162. j = {
  163. vim.diagnostic.goto_next,
  164. "Next Diagnostic",
  165. },
  166. k = {
  167. vim.diagnostic.goto_prev,
  168. "Prev Diagnostic",
  169. },
  170. l = { vim.lsp.codelens.run, "CodeLens Action" },
  171. p = {
  172. name = "Peek",
  173. d = { "<cmd>lua require('lvim.lsp.peek').Peek('definition')<cr>", "Definition" },
  174. t = { "<cmd>lua require('lvim.lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" },
  175. i = { "<cmd>lua require('lvim.lsp.peek').Peek('implementation')<cr>", "Implementation" },
  176. },
  177. q = { vim.diagnostic.setloclist, "Quickfix" },
  178. r = { vim.lsp.buf.rename, "Rename" },
  179. s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
  180. S = {
  181. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  182. "Workspace Symbols",
  183. },
  184. e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" },
  185. },
  186. L = {
  187. name = "+LunarVim",
  188. c = {
  189. "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",
  190. "Edit config.lua",
  191. },
  192. f = {
  193. "<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>",
  194. "Find LunarVim files",
  195. },
  196. g = {
  197. "<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>",
  198. "Grep LunarVim files",
  199. },
  200. k = { "<cmd>Telescope keymaps<cr>", "View LunarVim's keymappings" },
  201. i = {
  202. "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>",
  203. "Toggle LunarVim Info",
  204. },
  205. I = {
  206. "<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>",
  207. "View LunarVim's changelog",
  208. },
  209. l = {
  210. name = "+logs",
  211. d = {
  212. "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>",
  213. "view default log",
  214. },
  215. D = {
  216. "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>",
  217. "Open the default logfile",
  218. },
  219. l = {
  220. "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>",
  221. "view lsp log",
  222. },
  223. L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" },
  224. n = {
  225. "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
  226. "view neovim log",
  227. },
  228. N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
  229. p = {
  230. "<cmd>lua require('lvim.core.terminal').toggle_log_view(get_cache_dir() .. '/packer.nvim.log')<cr>",
  231. "view packer log",
  232. },
  233. P = { "<cmd>edit $LUNARVIM_CACHE_DIR/packer.nvim.log<cr>", "Open the Packer logfile" },
  234. },
  235. n = { "<cmd>Telescope notify<cr>", "View Notifications" },
  236. r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
  237. u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
  238. },
  239. s = {
  240. name = "Search",
  241. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  242. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  243. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  244. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  245. H = { "<cmd>Telescope highlights<cr>", "Find highlight groups" },
  246. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  247. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  248. R = { "<cmd>Telescope registers<cr>", "Registers" },
  249. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  250. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  251. C = { "<cmd>Telescope commands<cr>", "Commands" },
  252. p = {
  253. "<cmd>lua require('telescope.builtin.internal').colorscheme({enable_preview = true})<cr>",
  254. "Colorscheme with Preview",
  255. },
  256. },
  257. T = {
  258. name = "Treesitter",
  259. i = { ":TSConfigInfo<cr>", "Info" },
  260. },
  261. },
  262. }
  263. end
  264. M.setup = function()
  265. local which_key = require "which-key"
  266. which_key.setup(lvim.builtin.which_key.setup)
  267. local opts = lvim.builtin.which_key.opts
  268. local vopts = lvim.builtin.which_key.vopts
  269. local mappings = lvim.builtin.which_key.mappings
  270. local vmappings = lvim.builtin.which_key.vmappings
  271. which_key.register(mappings, opts)
  272. which_key.register(vmappings, vopts)
  273. if lvim.builtin.which_key.on_config_done then
  274. lvim.builtin.which_key.on_config_done(which_key)
  275. end
  276. end
  277. return M