init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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
  66. vim.api.nvim_set_keymap('n', '<Leader>f', ':Telescope find_files<CR>',
  67. {noremap = true, silent = true})
  68. -- dashboard
  69. vim.api.nvim_set_keymap('n', '<Leader>;', ':Dashboard<CR>',
  70. {noremap = true, silent = true})
  71. -- Comments
  72. vim.api.nvim_set_keymap("n", "<leader>/", ":CommentToggle<CR>",
  73. {noremap = true, silent = true})
  74. vim.api.nvim_set_keymap("v", "<leader>/", ":CommentToggle<CR>",
  75. {noremap = true, silent = true})
  76. -- close buffer
  77. vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>",
  78. {noremap = true, silent = true})
  79. -- TODO create entire treesitter section
  80. local mappings = {
  81. ["/"] = "Comment",
  82. ["c"] = "Close Buffer",
  83. ["e"] = "Explorer",
  84. ["f"] = "Find File",
  85. ["h"] = "No Highlight",
  86. b = {
  87. name = "Buffers",
  88. j = {"<cmd>BufferPick<cr>", "jump to buffer"},
  89. f = {"<cmd>Telescope buffers<cr>", "Find buffer"},
  90. w = {"<cmd>BufferWipeout<cr>", "wipeout buffer"},
  91. e = {
  92. "<cmd>BufferCloseAllButCurrent<cr>", "close all but current buffer"
  93. },
  94. h = {"<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left"},
  95. l = {
  96. "<cmd>BufferCloseBuffersRight<cr>",
  97. "close all BufferLines to the right"
  98. },
  99. D = {
  100. "<cmd>BufferOrderByDirectory<cr>",
  101. "sort BufferLines automatically by directory"
  102. },
  103. L = {
  104. "<cmd>BufferOrderByLanguage<cr>",
  105. "sort BufferLines automatically by language"
  106. }
  107. },
  108. -- diagnostics vanilla nvim
  109. -- -- diagnostic
  110. -- function lv_utils.get_all()
  111. -- vim.lsp.diagnostic.get_all()
  112. -- end
  113. -- function lv_utils.get_next()
  114. -- vim.lsp.diagnostic.get_next()
  115. -- end
  116. -- function lv_utils.get_prev()
  117. -- vim.lsp.diagnostic.get_prev()
  118. -- end
  119. -- function lv_utils.goto_next()
  120. -- vim.lsp.diagnostic.goto_next()
  121. -- end
  122. -- function lv_utils.goto_prev()
  123. -- vim.lsp.diagnostic.goto_prev()
  124. -- end
  125. -- function lv_utils.show_line_diagnostics()
  126. -- vim.lsp.diagnostic.show_line_diagnostics()
  127. -- end
  128. -- " Available Debug Adapters:
  129. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  130. -- " Adapter configuration and installation instructions:
  131. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  132. -- " Debug Adapter protocol:
  133. -- " https://microsoft.github.io/debug-adapter-protocol/
  134. -- " Debugging
  135. -- command! DebugToggleBreakpoint lua require'dap'.toggle_breakpoint()
  136. -- command! DebugStart lua require'dap'.continue()
  137. -- command! DebugContinue lua require'dap'.continue()
  138. -- command! DebugStepOver lua require'dap'.step_over()
  139. -- command! DebugStepOut lua require'dap'.step_out()
  140. -- command! DebugStepInto lua require'dap'.step_into()
  141. -- command! DebugToggleRepl lua require'dap'.repl.toggle()
  142. -- command! DebugGetSession lua require'dap'.session()
  143. -- D = {
  144. -- name = "Debug",
  145. -- b = {"<cmd>DebugToggleBreakpoint<cr>", "Toggle Breakpoint"},
  146. -- c = {"<cmd>DebugContinue<cr>", "Continue"},
  147. -- i = {"<cmd>DebugStepInto<cr>", "Step Into"},
  148. -- o = {"<cmd>DebugStepOver<cr>", "Step Over"},
  149. -- r = {"<cmd>DebugToggleRepl<cr>", "Toggle Repl"},
  150. -- s = {"<cmd>DebugStart<cr>", "Start"}
  151. -- },
  152. g = {
  153. name = "Git",
  154. j = {"<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk"},
  155. k = {"<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk"},
  156. l = {"<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame"},
  157. p = {"<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk"},
  158. r = {"<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk"},
  159. R = {"<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer"},
  160. s = {"<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk"},
  161. u = {
  162. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  163. "Undo Stage Hunk"
  164. },
  165. o = {"<cmd>Telescope git_status<cr>", "Open changed file"},
  166. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  167. c = {"<cmd>Telescope git_commits<cr>", "Checkout commit"},
  168. C = {
  169. "<cmd>Telescope git_bcommits<cr>",
  170. "Checkout commit(for current file)"
  171. }
  172. },
  173. l = {
  174. name = "LSP",
  175. a = {"<cmd>Lspsaga code_action<cr>", "Code Action"},
  176. A = {"<cmd>Lspsaga range_code_action<cr>", "Selected Action"},
  177. d = {
  178. "<cmd>Telescope lsp_document_diagnostics<cr>",
  179. "Document Diagnostics"
  180. },
  181. D = {
  182. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  183. "Workspace Diagnostics"
  184. },
  185. f = {"<cmd>lua vim.lsp.buf.formatting()<cr>", "Format"},
  186. h = {"<cmd>Lspsaga hover_doc<cr>", "Hover Doc"},
  187. i = {"<cmd>LspInfo<cr>", "Info"},
  188. j = {"<cmd>Lspsaga diagnostic_jump_prev<cr>", "Prev Diagnostic"},
  189. k = {"<cmd>Lspsaga diagnostic_jump_next<cr>", "Next Diagnostic"},
  190. l = {"<cmd>Lspsaga lsp_finder<cr>", "LSP Finder"},
  191. L = {"<cmd>Lspsaga show_line_diagnostics<cr>", "Line Diagnostics"},
  192. p = {"<cmd>Lspsaga preview_definition<cr>", "Preview Definition"},
  193. q = {"<cmd>Telescope quickfix<cr>", "Quickfix"},
  194. r = {"<cmd>Lspsaga rename<cr>", "Rename"},
  195. t = {"<cmd>LspTypeDefinition<cr>", "Type Definition"},
  196. x = {"<cmd>cclose<cr>", "Close Quickfix"},
  197. s = {"<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols"},
  198. S = {
  199. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  200. "Workspace Symbols"
  201. }
  202. },
  203. s = {
  204. name = "Search",
  205. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  206. c = {"<cmd>Telescope colorscheme<cr>", "Colorscheme"},
  207. -- d = {
  208. -- "<cmd>Telescope lsp_document_diagnostics<cr>",
  209. -- "Document Diagnostics"
  210. -- },
  211. -- D = {
  212. -- "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  213. -- "Workspace Diagnostics"
  214. -- },
  215. f = {"<cmd>Telescope find_files<cr>", "Find File"},
  216. h = {"<cmd>Telescope help_tags<cr>", "Find Help"},
  217. -- m = {"<cmd>Telescope marks<cr>", "Marks"},
  218. M = {"<cmd>Telescope man_pages<cr>", "Man Pages"},
  219. r = {"<cmd>Telescope oldfiles<cr>", "Open Recent File"},
  220. R = {"<cmd>Telescope registers<cr>", "Registers"},
  221. t = {"<cmd>Telescope live_grep<cr>", "Text"}
  222. },
  223. S = {
  224. name = "Session",
  225. s = {"<cmd>SessionSave<cr>", "Save Session"},
  226. l = {"<cmd>SessionLoad<cr>", "Load Session"}
  227. },
  228. T = {
  229. name = "Treesitter",
  230. i = {":TSConfigInfo<cr>", "Info"}
  231. }
  232. }
  233. if O.plugin.spectre.active then
  234. mappings['r'] = {
  235. name = "Replace",
  236. f = {
  237. "<cmd>lua require('spectre').open_file_search()<cr>", "Current File"
  238. },
  239. p = {"<cmd>lua require('spectre').open()<cr>", "Project"}
  240. }
  241. end
  242. if O.plugin.trouble.active then
  243. mappings['d'] = {
  244. name = "Diagnostics",
  245. t = {"<cmd>TroubleToggle<cr>", "trouble"},
  246. w = {"<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace"},
  247. d = {"<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document"},
  248. q = {"<cmd>TroubleToggle quickfix<cr>", "quickfix"},
  249. l = {"<cmd>TroubleToggle loclist<cr>", "loclist"},
  250. r = {"<cmd>TroubleToggle lsp_references<cr>", "references"}
  251. }
  252. end
  253. if O.plugin.gitlinker.active then mappings["gy"] = "Gitlink" end
  254. if O.plugin.ts_playground.active then
  255. vim.api.nvim_set_keymap("n", "<leader>Th",
  256. ":TSHighlightCapturesUnderCursor<CR>",
  257. {noremap = true, silent = true})
  258. mappings[""] = "Highlight Capture"
  259. end
  260. if O.plugin.zen.active then
  261. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>",
  262. {noremap = true, silent = true})
  263. mappings["z"] = "Zen"
  264. end
  265. if O.plugin.lazygit.active then
  266. vim.api.nvim_set_keymap("n", "<leader>gg", ":LazyGit<CR>",
  267. {noremap = true, silent = true})
  268. mappings["gg"] = "LazyGit"
  269. end
  270. if O.plugin.telescope_project.active then
  271. -- open projects
  272. vim.api.nvim_set_keymap('n', '<leader>p',
  273. ":lua require'telescope'.extensions.project.project{}<CR>",
  274. {noremap = true, silent = true})
  275. mappings["p"] = "Projects"
  276. end
  277. -- [";"] = "Dashboard",
  278. if O.lang.latex.active then
  279. mappings["L"] = {
  280. name = "+Latex",
  281. c = {"<cmd>VimtexCompile<cr>", "Toggle Compilation Mode"},
  282. f = {"<cmd>call vimtex#fzf#run()<cr>", "Fzf Find"},
  283. i = {"<cmd>VimtexInfo<cr>", "Project Information"},
  284. s = {"<cmd>VimtexStop<cr>", "Stop Project Compilation"},
  285. t = {"<cmd>VimtexTocToggle<cr>", "Toggle Table Of Content"},
  286. v = {"<cmd>VimtexView<cr>", "View PDF"}
  287. }
  288. end
  289. if O.lushmode then
  290. mappings["L"] = {
  291. name = "+Lush",
  292. l = {":Lushify<cr>", "Lushify"},
  293. x = {":lua require('lush').export_to_buffer(require('lush_theme.cool_name'))", "Lush Export"},
  294. t = {":LushRunTutorial<cr>", "Lush Tutorial"},
  295. q = {":LushRunQuickstart<cr>", "Lush Quickstart"}
  296. }
  297. end
  298. local wk = require("which-key")
  299. wk.register(mappings, opts)