which-key.lua 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. local M = {}
  2. M.config = function()
  3. lvim.builtin.which_key = {
  4. active = false,
  5. setup = {
  6. plugins = {
  7. marks = true, -- shows a list of your marks on ' and `
  8. registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
  9. -- the presets plugin, adds help for a bunch of default keybindings in Neovim
  10. -- No actual key bindings are created
  11. presets = {
  12. operators = false, -- adds help for operators like d, y, ...
  13. motions = false, -- adds help for motions
  14. text_objects = false, -- help for text objects triggered after entering an operator
  15. windows = true, -- default bindings on <c-w>
  16. nav = true, -- misc bindings to work with windows
  17. z = true, -- bindings for folds, spelling and others prefixed with z
  18. g = true, -- bindings for prefixed with g
  19. },
  20. spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints
  21. },
  22. icons = {
  23. breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
  24. separator = "➜", -- symbol used between a key and it's label
  25. group = "+", -- symbol prepended to a group
  26. },
  27. window = {
  28. border = "single", -- none, single, double, shadow
  29. position = "bottom", -- bottom, top
  30. margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
  31. padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
  32. },
  33. layout = {
  34. height = { min = 4, max = 25 }, -- min and max height of the columns
  35. width = { min = 20, max = 50 }, -- min and max width of the columns
  36. spacing = 3, -- spacing between columns
  37. },
  38. hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
  39. show_help = true, -- show help message on the command line when the popup is visible
  40. },
  41. opts = {
  42. mode = "n", -- NORMAL mode
  43. prefix = "<leader>",
  44. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  45. silent = true, -- use `silent` when creating keymaps
  46. noremap = true, -- use `noremap` when creating keymaps
  47. nowait = true, -- use `nowait` when creating keymaps
  48. },
  49. vopts = {
  50. mode = "v", -- VISUAL mode
  51. prefix = "<leader>",
  52. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  53. silent = true, -- use `silent` when creating keymaps
  54. noremap = true, -- use `noremap` when creating keymaps
  55. nowait = true, -- use `nowait` when creating keymaps
  56. },
  57. -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode.
  58. -- see https://neovim.io/doc/user/map.html#:map-cmd
  59. vmappings = {
  60. ["/"] = { ":CommentToggle<CR>", "Comment" },
  61. },
  62. mappings = {
  63. ["w"] = { "<cmd>w!<CR>", "Save" },
  64. ["q"] = { "<cmd>q!<CR>", "Quit" },
  65. ["/"] = { "<cmd>CommentToggle<CR>", "Comment" },
  66. ["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" },
  67. ["e"] = { "<cmd>lua require'core.nvimtree'.toggle_tree()<CR>", "Explorer" },
  68. ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" },
  69. ["h"] = { '<cmd>let @/=""<CR>', "No Highlight" },
  70. b = {
  71. name = "Buffers",
  72. j = { "<cmd>BufferPick<cr>", "jump to buffer" },
  73. f = { "<cmd>Telescope buffers<cr>", "Find buffer" },
  74. w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" },
  75. e = {
  76. "<cmd>BufferCloseAllButCurrent<cr>",
  77. "close all but current buffer",
  78. },
  79. h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" },
  80. l = {
  81. "<cmd>BufferCloseBuffersRight<cr>",
  82. "close all BufferLines to the right",
  83. },
  84. D = {
  85. "<cmd>BufferOrderByDirectory<cr>",
  86. "sort BufferLines automatically by directory",
  87. },
  88. L = {
  89. "<cmd>BufferOrderByLanguage<cr>",
  90. "sort BufferLines automatically by language",
  91. },
  92. },
  93. p = {
  94. name = "Packer",
  95. c = { "<cmd>PackerCompile<cr>", "Compile" },
  96. i = { "<cmd>PackerInstall<cr>", "Install" },
  97. r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" },
  98. s = { "<cmd>PackerSync<cr>", "Sync" },
  99. S = { "<cmd>PackerStatus<cr>", "Status" },
  100. u = { "<cmd>PackerUpdate<cr>", "Update" },
  101. },
  102. -- " Available Debug Adapters:
  103. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  104. -- " Adapter configuration and installation instructions:
  105. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  106. -- " Debug Adapter protocol:
  107. -- " https://microsoft.github.io/debug-adapter-protocol/
  108. -- " Debugging
  109. g = {
  110. name = "Git",
  111. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  112. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  113. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  114. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  115. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  116. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  117. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  118. u = {
  119. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  120. "Undo Stage Hunk",
  121. },
  122. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  123. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  124. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  125. C = {
  126. "<cmd>Telescope git_bcommits<cr>",
  127. "Checkout commit(for current file)",
  128. },
  129. },
  130. l = {
  131. name = "LSP",
  132. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  133. d = {
  134. "<cmd>Telescope lsp_document_diagnostics<cr>",
  135. "Document Diagnostics",
  136. },
  137. w = {
  138. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  139. "Workspace Diagnostics",
  140. },
  141. -- f = { "<cmd>silent FormatWrite<cr>", "Format" },
  142. f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" },
  143. i = { "<cmd>LspInfo<cr>", "Info" },
  144. j = {
  145. "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<cr>",
  146. "Next Diagnostic",
  147. },
  148. k = {
  149. "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>",
  150. "Prev Diagnostic",
  151. },
  152. p = {
  153. name = "Peek",
  154. d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" },
  155. t = { "<cmd>lua require('lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" },
  156. i = { "<cmd>lua require('lsp.peek').Peek('implementation')<cr>", "Implementation" },
  157. },
  158. q = { "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", "Quickfix" },
  159. r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
  160. s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
  161. S = {
  162. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  163. "Workspace Symbols",
  164. },
  165. },
  166. L = {
  167. name = "+LunarVim",
  168. k = { "<cmd>lua require('keymappings').print()<cr>", "View LunarVim's default keymappings" },
  169. i = {
  170. "<cmd>lua require('core.info').toggle_popup(vim.bo.filetype)<cr>",
  171. "Toggle LunarVim Info",
  172. },
  173. },
  174. s = {
  175. name = "Search",
  176. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  177. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  178. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  179. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  180. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  181. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  182. R = { "<cmd>Telescope registers<cr>", "Registers" },
  183. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  184. k = { "<cmd>Telescope keymaps<cr>", "Keymaps" },
  185. C = { "<cmd>Telescope commands<cr>", "Commands" },
  186. p = {
  187. "<cmd>lua require('telescope.builtin.internal').colorscheme({enable_preview = true})<cr>",
  188. "Colorscheme with Preview",
  189. },
  190. },
  191. T = {
  192. name = "Treesitter",
  193. i = { ":TSConfigInfo<cr>", "Info" },
  194. },
  195. },
  196. }
  197. end
  198. M.setup = function()
  199. -- if not package.loaded['which-key'] then
  200. -- return
  201. -- end
  202. local status_ok, which_key = pcall(require, "which-key")
  203. if not status_ok then
  204. return
  205. end
  206. which_key.setup(lvim.builtin.which_key.setup)
  207. local opts = lvim.builtin.which_key.opts
  208. local vopts = lvim.builtin.which_key.vopts
  209. local mappings = lvim.builtin.which_key.mappings
  210. local vmappings = lvim.builtin.which_key.vmappings
  211. local wk = require "which-key"
  212. wk.register(mappings, opts)
  213. wk.register(vmappings, vopts)
  214. end
  215. return M