init.lua 10 KB

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