init.lua 13 KB

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