which-key.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. spelling = {
  12. enabled = true,
  13. suggestions = 20,
  14. }, -- use which-key for spelling hints
  15. -- the presets plugin, adds help for a bunch of default keybindings in Neovim
  16. -- No actual key bindings are created
  17. presets = {
  18. operators = false, -- adds help for operators like d, y, ...
  19. motions = false, -- adds help for motions
  20. text_objects = false, -- help for text objects triggered after entering an operator
  21. windows = false, -- default bindings on <c-w>
  22. nav = false, -- misc bindings to work with windows
  23. z = false, -- bindings for folds, spelling and others prefixed with z
  24. g = false, -- bindings for prefixed with g
  25. },
  26. },
  27. -- add operators that will trigger motion and text object completion
  28. -- to enable all native operators, set the preset / operators plugin above
  29. operators = { gc = "Comments" },
  30. key_labels = {
  31. -- override the label used to display some keys. It doesn't effect WK in any other way.
  32. -- For example:
  33. -- ["<space>"] = "SPC",
  34. -- ["<cr>"] = "RET",
  35. -- ["<tab>"] = "TAB",
  36. },
  37. icons = {
  38. breadcrumb = lvim.icons.ui.DoubleChevronRight, -- symbol used in the command line area that shows your active key combo
  39. separator = lvim.icons.ui.BoldArrowRight, -- symbol used between a key and it's label
  40. group = lvim.icons.ui.Plus, -- symbol prepended to a group
  41. },
  42. popup_mappings = {
  43. scroll_down = "<c-d>", -- binding to scroll down inside the popup
  44. scroll_up = "<c-u>", -- binding to scroll up inside the popup
  45. },
  46. window = {
  47. border = "single", -- none, single, double, shadow
  48. position = "bottom", -- bottom, top
  49. margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
  50. padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
  51. winblend = 0,
  52. },
  53. layout = {
  54. height = { min = 4, max = 25 }, -- min and max height of the columns
  55. width = { min = 20, max = 50 }, -- min and max width of the columns
  56. spacing = 3, -- spacing between columns
  57. align = "left", -- align columns left, center or right
  58. },
  59. ignore_missing = true, -- enable this to hide mappings for which you didn't specify a label
  60. hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
  61. show_help = true, -- show help message on the command line when the popup is visible
  62. show_keys = true, -- show the currently pressed key and its label as a message in the command line
  63. triggers = "auto", -- automatically setup triggers
  64. -- triggers = {"<leader>"} -- or specify a list manually
  65. triggers_blacklist = {
  66. -- list of mode / prefixes that should never be hooked by WhichKey
  67. -- this is mostly relevant for key maps that start with a native binding
  68. -- most people should not need to change this
  69. i = { "j", "k" },
  70. v = { "j", "k" },
  71. },
  72. -- disable the WhichKey popup for certain buf types and file types.
  73. -- Disabled by default for Telescope
  74. disable = {
  75. buftypes = {},
  76. filetypes = { "TelescopePrompt" },
  77. },
  78. },
  79. opts = {
  80. mode = "n", -- NORMAL mode
  81. prefix = "<leader>",
  82. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  83. silent = true, -- use `silent` when creating keymaps
  84. noremap = true, -- use `noremap` when creating keymaps
  85. nowait = true, -- use `nowait` when creating keymaps
  86. },
  87. vopts = {
  88. mode = "v", -- VISUAL mode
  89. prefix = "<leader>",
  90. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  91. silent = true, -- use `silent` when creating keymaps
  92. noremap = true, -- use `noremap` when creating keymaps
  93. nowait = true, -- use `nowait` when creating keymaps
  94. },
  95. -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode.
  96. -- see https://neovim.io/doc/user/map.html#:map-cmd
  97. vmappings = {
  98. ["/"] = { "<Plug>(comment_toggle_linewise_visual)", "Comment toggle linewise (visual)" },
  99. l = {
  100. name = "LSP",
  101. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  102. },
  103. g = {
  104. name = "Git",
  105. r = { "<cmd>Gitsigns reset_hunk<cr>", "Reset Hunk" },
  106. s = { "<cmd>Gitsigns stage_hunk<cr>", "Stage Hunk" },
  107. },
  108. },
  109. mappings = {
  110. [";"] = { "<cmd>Alpha<CR>", "Dashboard" },
  111. ["w"] = { "<cmd>w!<CR>", "Save" },
  112. ["q"] = { "<cmd>confirm q<CR>", "Quit" },
  113. ["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" },
  114. ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },
  115. ["f"] = {
  116. function()
  117. require("lvim.core.telescope.custom-finders").find_project_files { previewer = false }
  118. end,
  119. "Find File",
  120. },
  121. ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
  122. ["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" },
  123. b = {
  124. name = "Buffers",
  125. j = { "<cmd>BufferLinePick<cr>", "Jump" },
  126. f = { "<cmd>Telescope buffers previewer=false<cr>", "Find" },
  127. b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" },
  128. n = { "<cmd>BufferLineCycleNext<cr>", "Next" },
  129. W = { "<cmd>noautocmd w<cr>", "Save without formatting (noautocmd)" },
  130. -- w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, -- TODO: implement this for bufferline
  131. e = {
  132. "<cmd>BufferLinePickClose<cr>",
  133. "Pick which buffer to close",
  134. },
  135. h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" },
  136. l = {
  137. "<cmd>BufferLineCloseRight<cr>",
  138. "Close all to the right",
  139. },
  140. D = {
  141. "<cmd>BufferLineSortByDirectory<cr>",
  142. "Sort by directory",
  143. },
  144. L = {
  145. "<cmd>BufferLineSortByExtension<cr>",
  146. "Sort by language",
  147. },
  148. },
  149. d = {
  150. name = "Debug",
  151. t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
  152. b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
  153. c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
  154. C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" },
  155. d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
  156. g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
  157. i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
  158. o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
  159. u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
  160. p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
  161. r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
  162. s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
  163. q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
  164. U = { "<cmd>lua require'dapui'.toggle({reset = true})<cr>", "Toggle UI" },
  165. },
  166. p = {
  167. name = "Plugins",
  168. i = { "<cmd>Lazy install<cr>", "Install" },
  169. s = { "<cmd>Lazy sync<cr>", "Sync" },
  170. S = { "<cmd>Lazy clear<cr>", "Status" },
  171. c = { "<cmd>Lazy clean<cr>", "Clean" },
  172. u = { "<cmd>Lazy update<cr>", "Update" },
  173. p = { "<cmd>Lazy profile<cr>", "Profile" },
  174. l = { "<cmd>Lazy log<cr>", "Log" },
  175. d = { "<cmd>Lazy debug<cr>", "Debug" },
  176. },
  177. -- " Available Debug Adapters:
  178. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  179. -- " Adapter configuration and installation instructions:
  180. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  181. -- " Debug Adapter protocol:
  182. -- " https://microsoft.github.io/debug-adapter-protocol/
  183. -- " Debugging
  184. g = {
  185. name = "Git",
  186. g = { "<cmd>lua require 'lvim.core.terminal'.lazygit_toggle()<cr>", "Lazygit" },
  187. j = { "<cmd>lua require 'gitsigns'.nav_hunk('next', {navigation_message = false})<cr>", "Next Hunk" },
  188. k = { "<cmd>lua require 'gitsigns'.nav_hunk('prev', {navigation_message = false})<cr>", "Prev Hunk" },
  189. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  190. L = { "<cmd>lua require 'gitsigns'.blame_line({full=true})<cr>", "Blame Line (full)" },
  191. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  192. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  193. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  194. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  195. u = {
  196. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  197. "Undo Stage Hunk",
  198. },
  199. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  200. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  201. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  202. C = {
  203. "<cmd>Telescope git_bcommits<cr>",
  204. "Checkout commit(for current file)",
  205. },
  206. d = {
  207. "<cmd>Gitsigns diffthis HEAD<cr>",
  208. "Git Diff",
  209. },
  210. },
  211. l = {
  212. name = "LSP",
  213. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  214. d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" },
  215. w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
  216. f = { "<cmd>lua require('lvim.lsp.utils').format()<cr>", "Format" },
  217. i = { "<cmd>LspInfo<cr>", "Info" },
  218. I = { "<cmd>Mason<cr>", "Mason Info" },
  219. j = {
  220. "<cmd>lua vim.diagnostic.goto_next()<cr>",
  221. "Next Diagnostic",
  222. },
  223. k = {
  224. "<cmd>lua vim.diagnostic.goto_prev()<cr>",
  225. "Prev Diagnostic",
  226. },
  227. l = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
  228. q = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" },
  229. r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
  230. s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
  231. S = {
  232. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  233. "Workspace Symbols",
  234. },
  235. e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" },
  236. },
  237. L = {
  238. name = "+LunarVim",
  239. c = {
  240. "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",
  241. "Edit config.lua",
  242. },
  243. d = { "<cmd>LvimDocs<cr>", "View LunarVim's docs" },
  244. f = {
  245. "<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>",
  246. "Find LunarVim files",
  247. },
  248. g = {
  249. "<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>",
  250. "Grep LunarVim files",
  251. },
  252. k = { "<cmd>Telescope keymaps<cr>", "View LunarVim's keymappings" },
  253. i = {
  254. "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>",
  255. "Toggle LunarVim Info",
  256. },
  257. I = {
  258. "<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>",
  259. "View LunarVim's changelog",
  260. },
  261. l = {
  262. name = "+logs",
  263. d = {
  264. "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>",
  265. "view default log",
  266. },
  267. D = {
  268. "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>",
  269. "Open the default logfile",
  270. },
  271. l = {
  272. "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>",
  273. "view lsp log",
  274. },
  275. L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" },
  276. n = {
  277. "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
  278. "view neovim log",
  279. },
  280. N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
  281. },
  282. r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
  283. u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
  284. },
  285. s = {
  286. name = "Search",
  287. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  288. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  289. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  290. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  291. H = { "<cmd>Telescope highlights<cr>", "Find highlight groups" },
  292. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  293. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  294. R = { "<cmd>Telescope registers<cr>", "Registers" },
  295. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  296. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  297. C = { "<cmd>Telescope commands<cr>", "Commands" },
  298. l = { "<cmd>Telescope resume<cr>", "Resume last search" },
  299. p = {
  300. "<cmd>lua require('telescope.builtin').colorscheme({enable_preview = true})<cr>",
  301. "Colorscheme with Preview",
  302. },
  303. },
  304. T = {
  305. name = "Treesitter",
  306. i = { ":TSConfigInfo<cr>", "Info" },
  307. },
  308. },
  309. }
  310. end
  311. M.setup = function()
  312. local which_key = require "which-key"
  313. which_key.setup(lvim.builtin.which_key.setup)
  314. local opts = lvim.builtin.which_key.opts
  315. local vopts = lvim.builtin.which_key.vopts
  316. local mappings = lvim.builtin.which_key.mappings
  317. local vmappings = lvim.builtin.which_key.vmappings
  318. which_key.register(mappings, opts)
  319. which_key.register(vmappings, vopts)
  320. if lvim.builtin.which_key.on_config_done then
  321. lvim.builtin.which_key.on_config_done(which_key)
  322. end
  323. end
  324. return M