init.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. -- Save
  77. vim.api.nvim_set_keymap("n", "<leader>w", ":w!<CR>", { noremap = true, silent = true })
  78. -- Quit
  79. vim.api.nvim_set_keymap("n", "<leader>q", ":q!<CR>", { noremap = true, silent = true })
  80. -- open lv-config
  81. vim.api.nvim_set_keymap(
  82. "n",
  83. "<leader>.",
  84. ":e " .. CONFIG_PATH .. "/lv-config.lua<CR>",
  85. { noremap = true, silent = true }
  86. )
  87. local mappings = {
  88. ["w"] = "Save",
  89. ["q"] = "Quit",
  90. ["."] = "LunarConfig",
  91. ["/"] = "Comment",
  92. ["c"] = "Close Buffer",
  93. ["e"] = "Explorer",
  94. ["f"] = "Find File",
  95. ["h"] = "No Highlight",
  96. [";"] = "Dashboard",
  97. p = {
  98. name = "Packer",
  99. c = { "<cmd>PackerCompile<cr>", "Compile" },
  100. i = { "<cmd>PackerInstall<cr>", "Install" },
  101. r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" },
  102. s = { "<cmd>PackerSync<cr>", "Sync" },
  103. u = { "<cmd>PackerUpdate<cr>", "Update" },
  104. },
  105. -- " Available Debug Adapters:
  106. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  107. -- " Adapter configuration and installation instructions:
  108. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  109. -- " Debug Adapter protocol:
  110. -- " https://microsoft.github.io/debug-adapter-protocol/
  111. -- " Debugging
  112. g = {
  113. name = "Git",
  114. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  115. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  116. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  117. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  118. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  119. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  120. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  121. u = {
  122. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  123. "Undo Stage Hunk",
  124. },
  125. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  126. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  127. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  128. C = {
  129. "<cmd>Telescope git_bcommits<cr>",
  130. "Checkout commit(for current file)",
  131. },
  132. },
  133. l = {
  134. name = "LSP",
  135. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  136. d = {
  137. "<cmd>Telescope lsp_document_diagnostics<cr>",
  138. "Document Diagnostics",
  139. },
  140. w = {
  141. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  142. "Workspace Diagnostics",
  143. },
  144. f = { "<cmd>Neoformat<cr>", "Format" },
  145. i = { "<cmd>LspInfo<cr>", "Info" },
  146. j = { "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", "Next Diagnostic" },
  147. k = { "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", "Prev Diagnostic" },
  148. q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
  149. r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
  150. s = {
  151. O.plugin.symbol_outline.active and "<cmd>SymbolsOutline<cr>" or "<cmd> Telescope lsp_document_symbols<cr>",
  152. "Document Symbols",
  153. },
  154. S = {
  155. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  156. "Workspace Symbols",
  157. },
  158. },
  159. s = {
  160. name = "Search",
  161. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  162. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  163. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  164. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  165. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  166. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  167. R = { "<cmd>Telescope registers<cr>", "Registers" },
  168. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  169. },
  170. T = {
  171. name = "Treesitter",
  172. i = { ":TSConfigInfo<cr>", "Info" },
  173. },
  174. }
  175. -- if O.plugin.trouble.active then
  176. -- mappings["d"] = {
  177. -- name = "Diagnostics",
  178. -- t = { "<cmd>TroubleToggle<cr>", "trouble" },
  179. -- w = { "<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace" },
  180. -- d = { "<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document" },
  181. -- q = { "<cmd>TroubleToggle quickfix<cr>", "quickfix" },
  182. -- l = { "<cmd>TroubleToggle loclist<cr>", "loclist" },
  183. -- r = { "<cmd>TroubleToggle lsp_references<cr>", "references" },
  184. -- }
  185. -- end
  186. if O.plugin.symbol_outline.active then
  187. vim.api.nvim_set_keymap("n", "<leader>o", ":SymbolsOutline<CR>", { noremap = true, silent = true })
  188. mappings["o"] = "Symbols outline"
  189. end
  190. if O.plugin.ts_playground.active then
  191. vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true })
  192. mappings[""] = "Highlight Capture"
  193. end
  194. if O.plugin.zen.active then
  195. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true })
  196. mappings["z"] = "Zen"
  197. end
  198. if O.plugin.telescope_project.active then
  199. -- open projects
  200. vim.api.nvim_set_keymap(
  201. "n",
  202. "<leader>P",
  203. ":lua require'telescope'.extensions.project.project{}<CR>",
  204. { noremap = true, silent = true }
  205. )
  206. mappings["P"] = "Projects"
  207. end
  208. if O.lushmode then
  209. mappings["L"] = {
  210. name = "+Lush",
  211. l = { ":Lushify<cr>", "Lushify" },
  212. x = { ":lua require('lush').export_to_buffer(require('lush_theme.cool_name'))", "Lush Export" },
  213. t = { ":LushRunTutorial<cr>", "Lush Tutorial" },
  214. q = { ":LushRunQuickstart<cr>", "Lush Quickstart" },
  215. }
  216. end
  217. if O.plugin.floatterm then
  218. vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
  219. mappings["gg"] = "LazyGit"
  220. end
  221. for k, v in pairs(O.user_which_key) do
  222. mappings[k] = v
  223. end
  224. local wk = require "which-key"
  225. wk.register(mappings, opts)