init.lua 11 KB

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