which-key.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 = false, -- 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 deafult 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. },
  100. mappings = {
  101. [";"] = { "<cmd>Alpha<CR>", "Dashboard" },
  102. ["w"] = { "<cmd>w!<CR>", "Save" },
  103. ["q"] = { "<cmd>lua require('lvim.utils.functions').smart_quit()<CR>", "Quit" },
  104. ["/"] = { "<Plug>(comment_toggle_linewise_current)", "Comment toggle current line" },
  105. ["c"] = { "<cmd>BufferKill<CR>", "Close Buffer" },
  106. ["f"] = {
  107. function()
  108. require("lvim.core.telescope.custom-finders").find_project_files { previewer = false }
  109. end,
  110. "Find File",
  111. },
  112. ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },
  113. ["e"] = { "<cmd>NvimTreeToggle<CR>", "Explorer" },
  114. b = {
  115. name = "Buffers",
  116. j = { "<cmd>BufferLinePick<cr>", "Jump" },
  117. f = { "<cmd>Telescope buffers previewer=false<cr>", "Find" },
  118. b = { "<cmd>BufferLineCyclePrev<cr>", "Previous" },
  119. n = { "<cmd>BufferLineCycleNext<cr>", "Next" },
  120. W = { "<cmd>noautocmd w<cr>", "Save without formatting (noautocmd)" },
  121. -- w = { "<cmd>BufferWipeout<cr>", "Wipeout" }, -- TODO: implement this for bufferline
  122. e = {
  123. "<cmd>BufferLinePickClose<cr>",
  124. "Pick which buffer to close",
  125. },
  126. h = { "<cmd>BufferLineCloseLeft<cr>", "Close all to the left" },
  127. l = {
  128. "<cmd>BufferLineCloseRight<cr>",
  129. "Close all to the right",
  130. },
  131. D = {
  132. "<cmd>BufferLineSortByDirectory<cr>",
  133. "Sort by directory",
  134. },
  135. L = {
  136. "<cmd>BufferLineSortByExtension<cr>",
  137. "Sort by language",
  138. },
  139. },
  140. d = {
  141. name = "Debug",
  142. t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" },
  143. b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" },
  144. c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" },
  145. C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" },
  146. d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" },
  147. g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" },
  148. i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" },
  149. o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" },
  150. u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" },
  151. p = { "<cmd>lua require'dap'.pause()<cr>", "Pause" },
  152. r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },
  153. s = { "<cmd>lua require'dap'.continue()<cr>", "Start" },
  154. q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },
  155. U = { "<cmd>lua require'dapui'.toggle({reset = true})<cr>", "Toggle UI" },
  156. },
  157. p = {
  158. name = "Plugins",
  159. i = { "<cmd>Lazy install<cr>", "Install" },
  160. s = { "<cmd>Lazy sync<cr>", "Sync" },
  161. S = { "<cmd>Lazy clear<cr>", "Status" },
  162. c = { "<cmd>Lazy clean<cr>", "Clean" },
  163. u = { "<cmd>Lazy update<cr>", "Update" },
  164. p = { "<cmd>Lazy profile<cr>", "Profile" },
  165. l = { "<cmd>Lazy log<cr>", "Log" },
  166. d = { "<cmd>Lazy debug<cr>", "Debug" },
  167. },
  168. -- " Available Debug Adapters:
  169. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  170. -- " Adapter configuration and installation instructions:
  171. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  172. -- " Debug Adapter protocol:
  173. -- " https://microsoft.github.io/debug-adapter-protocol/
  174. -- " Debugging
  175. g = {
  176. name = "Git",
  177. g = { "<cmd>lua require 'lvim.core.terminal'.lazygit_toggle()<cr>", "Lazygit" },
  178. j = { "<cmd>lua require 'gitsigns'.next_hunk({navigation_message = false})<cr>", "Next Hunk" },
  179. k = { "<cmd>lua require 'gitsigns'.prev_hunk({navigation_message = false})<cr>", "Prev Hunk" },
  180. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  181. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  182. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  183. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  184. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  185. u = {
  186. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  187. "Undo Stage Hunk",
  188. },
  189. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  190. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  191. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  192. C = {
  193. "<cmd>Telescope git_bcommits<cr>",
  194. "Checkout commit(for current file)",
  195. },
  196. d = {
  197. "<cmd>Gitsigns diffthis HEAD<cr>",
  198. "Git Diff",
  199. },
  200. },
  201. l = {
  202. name = "LSP",
  203. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  204. d = { "<cmd>Telescope diagnostics bufnr=0 theme=get_ivy<cr>", "Buffer Diagnostics" },
  205. w = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
  206. f = { require("lvim.lsp.utils").format, "Format" },
  207. i = { "<cmd>LspInfo<cr>", "Info" },
  208. I = { "<cmd>Mason<cr>", "Mason Info" },
  209. j = {
  210. vim.diagnostic.goto_next,
  211. "Next Diagnostic",
  212. },
  213. k = {
  214. vim.diagnostic.goto_prev,
  215. "Prev Diagnostic",
  216. },
  217. l = { vim.lsp.codelens.run, "CodeLens Action" },
  218. q = { vim.diagnostic.setloclist, "Quickfix" },
  219. r = { vim.lsp.buf.rename, "Rename" },
  220. s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
  221. S = {
  222. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  223. "Workspace Symbols",
  224. },
  225. e = { "<cmd>Telescope quickfix<cr>", "Telescope Quickfix" },
  226. },
  227. L = {
  228. name = "+LunarVim",
  229. c = {
  230. "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",
  231. "Edit config.lua",
  232. },
  233. d = { "<cmd>LvimDocs<cr>", "View LunarVim's docs" },
  234. f = {
  235. "<cmd>lua require('lvim.core.telescope.custom-finders').find_lunarvim_files()<cr>",
  236. "Find LunarVim files",
  237. },
  238. g = {
  239. "<cmd>lua require('lvim.core.telescope.custom-finders').grep_lunarvim_files()<cr>",
  240. "Grep LunarVim files",
  241. },
  242. k = { "<cmd>Telescope keymaps<cr>", "View LunarVim's keymappings" },
  243. i = {
  244. "<cmd>lua require('lvim.core.info').toggle_popup(vim.bo.filetype)<cr>",
  245. "Toggle LunarVim Info",
  246. },
  247. I = {
  248. "<cmd>lua require('lvim.core.telescope.custom-finders').view_lunarvim_changelog()<cr>",
  249. "View LunarVim's changelog",
  250. },
  251. l = {
  252. name = "+logs",
  253. d = {
  254. "<cmd>lua require('lvim.core.terminal').toggle_log_view(require('lvim.core.log').get_path())<cr>",
  255. "view default log",
  256. },
  257. D = {
  258. "<cmd>lua vim.fn.execute('edit ' .. require('lvim.core.log').get_path())<cr>",
  259. "Open the default logfile",
  260. },
  261. l = {
  262. "<cmd>lua require('lvim.core.terminal').toggle_log_view(vim.lsp.get_log_path())<cr>",
  263. "view lsp log",
  264. },
  265. L = { "<cmd>lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())<cr>", "Open the LSP logfile" },
  266. n = {
  267. "<cmd>lua require('lvim.core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))<cr>",
  268. "view neovim log",
  269. },
  270. N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
  271. },
  272. r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
  273. u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
  274. },
  275. s = {
  276. name = "Search",
  277. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  278. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  279. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  280. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  281. H = { "<cmd>Telescope highlights<cr>", "Find highlight groups" },
  282. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  283. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  284. R = { "<cmd>Telescope registers<cr>", "Registers" },
  285. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  286. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  287. C = { "<cmd>Telescope commands<cr>", "Commands" },
  288. p = {
  289. "<cmd>lua require('telescope.builtin').colorscheme({enable_preview = true})<cr>",
  290. "Colorscheme with Preview",
  291. },
  292. },
  293. T = {
  294. name = "Treesitter",
  295. i = { ":TSConfigInfo<cr>", "Info" },
  296. },
  297. },
  298. }
  299. end
  300. M.setup = function()
  301. local which_key = require "which-key"
  302. which_key.setup(lvim.builtin.which_key.setup)
  303. local opts = lvim.builtin.which_key.opts
  304. local vopts = lvim.builtin.which_key.vopts
  305. local mappings = lvim.builtin.which_key.mappings
  306. local vmappings = lvim.builtin.which_key.vmappings
  307. which_key.register(mappings, opts)
  308. which_key.register(vmappings, vopts)
  309. if lvim.builtin.which_key.on_config_done then
  310. lvim.builtin.which_key.on_config_done(which_key)
  311. end
  312. end
  313. return M