init.lua 9.8 KB

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