init.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. if not package.loaded['which-key'] then
  2. return
  3. end
  4. require("which-key").setup {
  5. plugins = {
  6. marks = true, -- shows a list of your marks on ' and `
  7. registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
  8. -- the presets plugin, adds help for a bunch of default keybindings in Neovim
  9. -- No actual key bindings are created
  10. presets = {
  11. operators = false, -- adds help for operators like d, y, ...
  12. motions = false, -- adds help for motions
  13. text_objects = false, -- help for text objects triggered after entering an operator
  14. windows = true, -- default bindings on <c-w>
  15. nav = true, -- misc bindings to work with windows
  16. z = true, -- bindings for folds, spelling and others prefixed with z
  17. g = true -- bindings for prefixed with g
  18. }
  19. },
  20. icons = {
  21. breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
  22. separator = "➜", -- symbol used between a key and it's label
  23. group = "+" -- symbol prepended to a group
  24. },
  25. window = {
  26. border = "single", -- none, single, double, shadow
  27. position = "bottom", -- bottom, top
  28. margin = {1, 0, 1, 0}, -- extra window margin [top, right, bottom, left]
  29. padding = {2, 2, 2, 2} -- extra window padding [top, right, bottom, left]
  30. },
  31. layout = {
  32. height = {min = 4, max = 25}, -- min and max height of the columns
  33. width = {min = 20, max = 50}, -- min and max width of the columns
  34. spacing = 3 -- spacing between columns
  35. },
  36. hidden = {"<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
  37. show_help = true -- show help message on the command line when the popup is visible
  38. }
  39. -- Set leader
  40. if O.leader_key == ' ' or O.leader_key == 'space' then
  41. vim.api.nvim_set_keymap('n', '<Space>', '<NOP>',
  42. {noremap = true, silent = true})
  43. vim.g.mapleader = ' '
  44. else
  45. vim.api.nvim_set_keymap('n', O.leader_key, '<NOP>',
  46. {noremap = true, silent = true})
  47. vim.g.mapleader = O.leader_key
  48. end
  49. local opts = {
  50. mode = "n", -- NORMAL 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 = false -- use `nowait` when creating keymaps
  56. }
  57. -- no hl
  58. vim.api.nvim_set_keymap('n', '<Leader>h', ':let @/=""<CR>',
  59. {noremap = true, silent = true})
  60. -- explorer
  61. -- TODO this introduces some bugs unfortunately
  62. vim.api.nvim_set_keymap('n', '<Leader>e',
  63. ":lua require'lv-nvimtree'.toggle_tree()<CR>",
  64. {noremap = true, silent = true})
  65. -- vim.api.nvim_set_keymap('n', '<Leader>e',
  66. -- ":NvimTreeToggle<CR>",
  67. -- {noremap = true, silent = true})
  68. -- telescope or snap
  69. if O.plugin.snap.active then
  70. vim.api.nvim_set_keymap('n', '<Leader>f', ':Snap find_files<CR>',
  71. {noremap = true, silent = true})
  72. else
  73. vim.api.nvim_set_keymap('n', '<Leader>f', ':Telescope find_files<CR>',
  74. {noremap = true, silent = true})
  75. end
  76. -- dashboard
  77. vim.api.nvim_set_keymap('n', '<Leader>;', ':Dashboard<CR>',
  78. {noremap = true, silent = true})
  79. -- Comments
  80. vim.api.nvim_set_keymap("n", "<leader>/", ":CommentToggle<CR>",
  81. {noremap = true, silent = true})
  82. vim.api.nvim_set_keymap("v", "<leader>/", ":CommentToggle<CR>",
  83. {noremap = true, silent = true})
  84. -- close buffer
  85. vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>",
  86. {noremap = true, silent = true})
  87. -- TODO create entire treesitter section
  88. local mappings = {
  89. ["/"] = "Comment",
  90. ["c"] = "Close Buffer",
  91. ["e"] = "Explorer",
  92. ["f"] = "Find File",
  93. ["h"] = "No Highlight",
  94. b = {
  95. name = "Buffers",
  96. j = {"<cmd>BufferPick<cr>", "jump to buffer"},
  97. f = {O.plugin.snap.active and "<cmd>Snap buffers<cr>" or "<cmd>Telescope buffers<cr>", "Find buffer"},
  98. w = {"<cmd>BufferWipeout<cr>", "wipeout buffer"},
  99. e = {
  100. "<cmd>BufferCloseAllButCurrent<cr>", "close all but current buffer"
  101. },
  102. h = {"<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left"},
  103. l = {
  104. "<cmd>BufferCloseBuffersRight<cr>",
  105. "close all BufferLines to the right"
  106. },
  107. D = {
  108. "<cmd>BufferOrderByDirectory<cr>",
  109. "sort BufferLines automatically by directory"
  110. },
  111. L = {
  112. "<cmd>BufferOrderByLanguage<cr>",
  113. "sort BufferLines automatically by language"
  114. }
  115. },
  116. -- diagnostics vanilla nvim
  117. -- -- diagnostic
  118. -- function lv_utils.get_all()
  119. -- vim.lsp.diagnostic.get_all()
  120. -- end
  121. -- function lv_utils.get_next()
  122. -- vim.lsp.diagnostic.get_next()
  123. -- end
  124. -- function lv_utils.get_prev()
  125. -- vim.lsp.diagnostic.get_prev()
  126. -- end
  127. -- function lv_utils.goto_next()
  128. -- vim.lsp.diagnostic.goto_next()
  129. -- end
  130. -- function lv_utils.goto_prev()
  131. -- vim.lsp.diagnostic.goto_prev()
  132. -- end
  133. -- function lv_utils.show_line_diagnostics()
  134. -- vim.lsp.diagnostic.show_line_diagnostics()
  135. -- end
  136. -- " Available Debug Adapters:
  137. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  138. -- " Adapter configuration and installation instructions:
  139. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  140. -- " Debug Adapter protocol:
  141. -- " https://microsoft.github.io/debug-adapter-protocol/
  142. -- " Debugging
  143. -- command! DebugToggleBreakpoint lua require'dap'.toggle_breakpoint()
  144. -- command! DebugStart lua require'dap'.continue()
  145. -- command! DebugContinue lua require'dap'.continue()
  146. -- command! DebugStepOver lua require'dap'.step_over()
  147. -- command! DebugStepOut lua require'dap'.step_out()
  148. -- command! DebugStepInto lua require'dap'.step_into()
  149. -- command! DebugToggleRepl lua require'dap'.repl.toggle()
  150. -- command! DebugGetSession lua require'dap'.session()
  151. -- D = {
  152. -- name = "Debug",
  153. -- b = {"<cmd>DebugToggleBreakpoint<cr>", "Toggle Breakpoint"},
  154. -- c = {"<cmd>DebugContinue<cr>", "Continue"},
  155. -- i = {"<cmd>DebugStepInto<cr>", "Step Into"},
  156. -- o = {"<cmd>DebugStepOver<cr>", "Step Over"},
  157. -- r = {"<cmd>DebugToggleRepl<cr>", "Toggle Repl"},
  158. -- s = {"<cmd>DebugStart<cr>", "Start"}
  159. -- },
  160. g = {
  161. name = "Git",
  162. j = {"<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk"},
  163. k = {"<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk"},
  164. l = {"<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame"},
  165. p = {"<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk"},
  166. r = {"<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk"},
  167. R = {"<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer"},
  168. s = {"<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk"},
  169. u = {
  170. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  171. "Undo Stage Hunk"
  172. },
  173. o = {"<cmd>Telescope git_status<cr>", "Open changed file"},
  174. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  175. c = {"<cmd>Telescope git_commits<cr>", "Checkout commit"},
  176. C = {
  177. "<cmd>Telescope git_bcommits<cr>",
  178. "Checkout commit(for current file)"
  179. }
  180. },
  181. l = {
  182. name = "LSP",
  183. a = {"<cmd>Lspsaga code_action<cr>", "Code Action"},
  184. A = {"<cmd>Lspsaga range_code_action<cr>", "Selected Action"},
  185. d = {
  186. "<cmd>Telescope lsp_document_diagnostics<cr>",
  187. "Document Diagnostics"
  188. },
  189. D = {
  190. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  191. "Workspace Diagnostics"
  192. },
  193. f = {"<cmd>lua vim.lsp.buf.formatting()<cr>", "Format"},
  194. h = {"<cmd>Lspsaga hover_doc<cr>", "Hover Doc"},
  195. i = {"<cmd>LspInfo<cr>", "Info"},
  196. j = {"<cmd>Lspsaga diagnostic_jump_prev<cr>", "Prev Diagnostic"},
  197. k = {"<cmd>Lspsaga diagnostic_jump_next<cr>", "Next Diagnostic"},
  198. l = {"<cmd>Lspsaga lsp_finder<cr>", "LSP Finder"},
  199. L = {"<cmd>Lspsaga show_line_diagnostics<cr>", "Line Diagnostics"},
  200. p = {"<cmd>Lspsaga preview_definition<cr>", "Preview Definition"},
  201. q = {"<cmd>Telescope quickfix<cr>", "Quickfix"},
  202. r = {"<cmd>Lspsaga rename<cr>", "Rename"},
  203. t = {"<cmd>LspTypeDefinition<cr>", "Type Definition"},
  204. x = {"<cmd>cclose<cr>", "Close Quickfix"},
  205. s = {O.plugin.symbol_outline.active and "<cmd>SymbolsOutline<cr>" or
  206. "<cmd> Telescope lsp_document_symbols<cr>", "Document Symbols"},
  207. S = {
  208. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  209. "Workspace Symbols"
  210. }
  211. },
  212. s = {
  213. name = "Search",
  214. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  215. c = {"<cmd>Telescope colorscheme<cr>", "Colorscheme"},
  216. -- d = {
  217. -- "<cmd>Telescope lsp_document_diagnostics<cr>",
  218. -- "Document Diagnostics"
  219. -- },
  220. -- D = {
  221. -- "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  222. -- "Workspace Diagnostics"
  223. -- },
  224. f = {O.plugin.snap.active and "<cmd>Snap find_files<cr>" or "<cmd>Telescope find_files<cr>", "Find File"},
  225. h = {"<cmd>Telescope help_tags<cr>", "Find Help"},
  226. -- m = {"<cmd>Telescope marks<cr>", "Marks"},
  227. M = {"<cmd>Telescope man_pages<cr>", "Man Pages"},
  228. r = {O.plugin.snap.active and "<cmd>Snap oldfiles<cr>" or "<cmd>Telescope oldfiles<cr>", "Open Recent File"},
  229. R = {"<cmd>Telescope registers<cr>", "Registers"},
  230. t = {O.plugin.snap.active and "<cmd>Snap live_grep<cr>" or "<cmd>Telescope live_grep<cr>", "Text"}
  231. },
  232. S = {
  233. name = "Session",
  234. s = {"<cmd>SessionSave<cr>", "Save Session"},
  235. l = {"<cmd>SessionLoad<cr>", "Load Session"}
  236. },
  237. T = {
  238. name = "Treesitter",
  239. i = {":TSConfigInfo<cr>", "Info"}
  240. }
  241. }
  242. if O.plugin.spectre.active then
  243. mappings['r'] = {
  244. name = "Replace",
  245. f = {
  246. "<cmd>lua require('spectre').open_file_search()<cr>", "Current File"
  247. },
  248. p = {"<cmd>lua require('spectre').open()<cr>", "Project"}
  249. }
  250. end
  251. if O.plugin.trouble.active then
  252. mappings['d'] = {
  253. name = "Diagnostics",
  254. t = {"<cmd>TroubleToggle<cr>", "trouble"},
  255. w = {"<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace"},
  256. d = {"<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document"},
  257. q = {"<cmd>TroubleToggle quickfix<cr>", "quickfix"},
  258. l = {"<cmd>TroubleToggle loclist<cr>", "loclist"},
  259. r = {"<cmd>TroubleToggle lsp_references<cr>", "references"}
  260. }
  261. end
  262. if O.plugin.gitlinker.active then mappings["gy"] = "Gitlink" end
  263. if O.plugin.ts_playground.active then
  264. vim.api.nvim_set_keymap("n", "<leader>Th",
  265. ":TSHighlightCapturesUnderCursor<CR>",
  266. {noremap = true, silent = true})
  267. mappings[""] = "Highlight Capture"
  268. end
  269. if O.plugin.zen.active then
  270. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>",
  271. {noremap = true, silent = true})
  272. mappings["z"] = "Zen"
  273. end
  274. if O.plugin.lazygit.active then
  275. vim.api.nvim_set_keymap("n", "<leader>gg", ":LazyGit<CR>",
  276. {noremap = true, silent = true})
  277. mappings["gg"] = "LazyGit"
  278. end
  279. if O.plugin.telescope_project.active then
  280. -- open projects
  281. vim.api.nvim_set_keymap('n', '<leader>p',
  282. ":lua require'telescope'.extensions.project.project{}<CR>",
  283. {noremap = true, silent = true})
  284. mappings["p"] = "Projects"
  285. end
  286. -- [";"] = "Dashboard",
  287. if O.lang.latex.active then
  288. mappings["L"] = {
  289. name = "+Latex",
  290. c = {"<cmd>VimtexCompile<cr>", "Toggle Compilation Mode"},
  291. f = {"<cmd>call vimtex#fzf#run()<cr>", "Fzf Find"},
  292. i = {"<cmd>VimtexInfo<cr>", "Project Information"},
  293. s = {"<cmd>VimtexStop<cr>", "Stop Project Compilation"},
  294. t = {"<cmd>VimtexTocToggle<cr>", "Toggle Table Of Content"},
  295. v = {"<cmd>VimtexView<cr>", "View PDF"}
  296. }
  297. end
  298. if O.lushmode then
  299. mappings["L"] = {
  300. name = "+Lush",
  301. l = {":Lushify<cr>", "Lushify"},
  302. x = {":lua require('lush').export_to_buffer(require('lush_theme.cool_name'))", "Lush Export"},
  303. t = {":LushRunTutorial<cr>", "Lush Tutorial"},
  304. q = {":LushRunQuickstart<cr>", "Lush Quickstart"}
  305. }
  306. end
  307. local wk = require("which-key")
  308. wk.register(mappings, opts)