init.lua 12 KB

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