init.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. r = {
  204. name = "Replace",
  205. f = {
  206. "<cmd>lua require('spectre').open_file_search()<cr>", "Current File"
  207. },
  208. p = {"<cmd>lua require('spectre').open()<cr>", "Project"}
  209. },
  210. s = {
  211. name = "Search",
  212. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  213. c = {"<cmd>Telescope colorscheme<cr>", "Colorscheme"},
  214. -- d = {
  215. -- "<cmd>Telescope lsp_document_diagnostics<cr>",
  216. -- "Document Diagnostics"
  217. -- },
  218. -- D = {
  219. -- "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  220. -- "Workspace Diagnostics"
  221. -- },
  222. f = {"<cmd>Telescope find_files<cr>", "Find File"},
  223. h = {"<cmd>Telescope help_tags<cr>", "Find Help"},
  224. -- m = {"<cmd>Telescope marks<cr>", "Marks"},
  225. M = {"<cmd>Telescope man_pages<cr>", "Man Pages"},
  226. r = {"<cmd>Telescope oldfiles<cr>", "Open Recent File"},
  227. R = {"<cmd>Telescope registers<cr>", "Registers"},
  228. t = {"<cmd>Telescope live_grep<cr>", "Text"}
  229. },
  230. S = {
  231. name = "Session",
  232. s = {"<cmd>SessionSave<cr>", "Save Session"},
  233. l = {"<cmd>SessionLoad<cr>", "Load Session"}
  234. }
  235. }
  236. if O.plugin.trouble.active then
  237. mappings['d'] = {
  238. name = "Diagnostics",
  239. t = {"<cmd>TroubleToggle<cr>", "trouble"},
  240. w = {"<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace"},
  241. d = {"<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document"},
  242. q = {"<cmd>TroubleToggle quickfix<cr>", "quickfix"},
  243. l = {"<cmd>TroubleToggle loclist<cr>", "loclist"},
  244. r = {"<cmd>TroubleToggle lsp_references<cr>", "references"}
  245. }
  246. end
  247. if O.plugin.gitlinker.active then mappings["gy"] = "Gitlink" end
  248. if O.plugin.zen.active then
  249. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>",
  250. {noremap = true, silent = true})
  251. mappings["z"] = "Zen"
  252. end
  253. if O.plugin.lazygit.active then
  254. vim.api.nvim_set_keymap("n", "<leader>gg", ":LazyGit<CR>",
  255. {noremap = true, silent = true})
  256. mappings["gg"] = "LazyGit"
  257. end
  258. if O.plugin.telescope_project.active then
  259. -- open projects
  260. vim.api.nvim_set_keymap('n', '<leader>p',
  261. ":lua require'telescope'.extensions.project.project{}<CR>",
  262. {noremap = true, silent = true})
  263. mappings["p"] = "Projects"
  264. end
  265. -- [";"] = "Dashboard",
  266. if O.lang.latex.active then
  267. mappings["L"] = {
  268. name = "+Latex",
  269. c = {"<cmd>VimtexCompile<cr>", "Toggle Compilation Mode"},
  270. f = {"<cmd>call vimtex#fzf#run()<cr>", "Fzf Find"},
  271. i = {"<cmd>VimtexInfo<cr>", "Project Information"},
  272. s = {"<cmd>VimtexStop<cr>", "Stop Project Compilation"},
  273. t = {"<cmd>VimtexTocToggle<cr>", "Toggle Table Of Content"},
  274. v = {"<cmd>VimtexView<cr>", "View PDF"}
  275. }
  276. end
  277. local wk = require("which-key")
  278. wk.register(mappings, opts)