init.lua 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints
  24. },
  25. icons = {
  26. breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
  27. separator = "➜", -- symbol used between a key and it's label
  28. group = "+", -- symbol prepended to a group
  29. },
  30. window = {
  31. border = "single", -- none, single, double, shadow
  32. position = "bottom", -- bottom, top
  33. margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]
  34. padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left]
  35. },
  36. layout = {
  37. height = { min = 4, max = 25 }, -- min and max height of the columns
  38. width = { min = 20, max = 50 }, -- min and max width of the columns
  39. spacing = 3, -- spacing between columns
  40. },
  41. hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
  42. show_help = true, -- show help message on the command line when the popup is visible
  43. }
  44. -- Set leader
  45. if O.leader_key == " " or O.leader_key == "space" then
  46. vim.api.nvim_set_keymap("n", "<Space>", "<NOP>", { noremap = true, silent = true })
  47. vim.g.mapleader = " "
  48. else
  49. vim.api.nvim_set_keymap("n", O.leader_key, "<NOP>", { noremap = true, silent = true })
  50. vim.g.mapleader = O.leader_key
  51. end
  52. local opts = {
  53. mode = "n", -- NORMAL mode
  54. prefix = "<leader>",
  55. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  56. silent = true, -- use `silent` when creating keymaps
  57. noremap = true, -- use `noremap` when creating keymaps
  58. nowait = false, -- use `nowait` when creating keymaps
  59. }
  60. -- no hl
  61. vim.api.nvim_set_keymap("n", "<Leader>h", ':let @/=""<CR>', { noremap = true, silent = true })
  62. -- explorer
  63. vim.api.nvim_set_keymap(
  64. "n",
  65. "<Leader>e",
  66. ":lua require'lv-nvimtree'.toggle_tree()<CR>",
  67. { noremap = true, silent = true }
  68. )
  69. vim.api.nvim_set_keymap("n", "<Leader>f", ":Telescope find_files<CR>", { noremap = true, silent = true })
  70. -- dashboard
  71. vim.api.nvim_set_keymap("n", "<Leader>;", ":Dashboard<CR>", { noremap = true, silent = true })
  72. -- Comments
  73. vim.api.nvim_set_keymap("n", "<leader>/", ":CommentToggle<CR>", { noremap = true, silent = true })
  74. vim.api.nvim_set_keymap("v", "<leader>/", ":CommentToggle<CR>", { noremap = true, silent = true })
  75. -- close buffer
  76. vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>", { noremap = true, silent = true })
  77. -- Save
  78. vim.api.nvim_set_keymap("n", "<leader>w", ":w!<CR>", { noremap = true, silent = true })
  79. -- Quit
  80. vim.api.nvim_set_keymap("n", "<leader>q", ":q!<CR>", { noremap = true, silent = true })
  81. -- open lv-config
  82. vim.api.nvim_set_keymap(
  83. "n",
  84. "<leader>.",
  85. ":e " .. CONFIG_PATH .. "/lv-config.lua<CR>",
  86. { noremap = true, silent = true }
  87. )
  88. local mappings = {
  89. ["w"] = "Save",
  90. ["q"] = "Quit",
  91. ["."] = "LunarConfig",
  92. ["/"] = "Comment",
  93. ["c"] = "Close Buffer",
  94. ["e"] = "Explorer",
  95. ["f"] = "Find File",
  96. ["h"] = "No Highlight",
  97. [";"] = "Dashboard",
  98. p = {
  99. name = "Packer",
  100. c = { "<cmd>PackerCompile<cr>", "Compile" },
  101. i = { "<cmd>PackerInstall<cr>", "Install" },
  102. r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" },
  103. s = { "<cmd>PackerSync<cr>", "Sync" },
  104. u = { "<cmd>PackerUpdate<cr>", "Update" },
  105. },
  106. -- " Available Debug Adapters:
  107. -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
  108. -- " Adapter configuration and installation instructions:
  109. -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation
  110. -- " Debug Adapter protocol:
  111. -- " https://microsoft.github.io/debug-adapter-protocol/
  112. -- " Debugging
  113. g = {
  114. name = "Git",
  115. j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" },
  116. k = { "<cmd>lua require 'gitsigns'.prev_hunk()<cr>", "Prev Hunk" },
  117. l = { "<cmd>lua require 'gitsigns'.blame_line()<cr>", "Blame" },
  118. p = { "<cmd>lua require 'gitsigns'.preview_hunk()<cr>", "Preview Hunk" },
  119. r = { "<cmd>lua require 'gitsigns'.reset_hunk()<cr>", "Reset Hunk" },
  120. R = { "<cmd>lua require 'gitsigns'.reset_buffer()<cr>", "Reset Buffer" },
  121. s = { "<cmd>lua require 'gitsigns'.stage_hunk()<cr>", "Stage Hunk" },
  122. u = {
  123. "<cmd>lua require 'gitsigns'.undo_stage_hunk()<cr>",
  124. "Undo Stage Hunk",
  125. },
  126. o = { "<cmd>Telescope git_status<cr>", "Open changed file" },
  127. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  128. c = { "<cmd>Telescope git_commits<cr>", "Checkout commit" },
  129. C = {
  130. "<cmd>Telescope git_bcommits<cr>",
  131. "Checkout commit(for current file)",
  132. },
  133. },
  134. l = {
  135. name = "LSP",
  136. a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" },
  137. d = {
  138. "<cmd>Telescope lsp_document_diagnostics<cr>",
  139. "Document Diagnostics",
  140. },
  141. w = {
  142. "<cmd>Telescope lsp_workspace_diagnostics<cr>",
  143. "Workspace Diagnostics",
  144. },
  145. f = { "<cmd>Neoformat<cr>", "Format" },
  146. i = { "<cmd>LspInfo<cr>", "Info" },
  147. j = { "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", "Next Diagnostic" },
  148. k = { "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", "Prev Diagnostic" },
  149. q = { "<cmd>Telescope quickfix<cr>", "Quickfix" },
  150. r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
  151. s = {
  152. O.plugin.symbol_outline.active and "<cmd>SymbolsOutline<cr>" or "<cmd> Telescope lsp_document_symbols<cr>",
  153. "Document Symbols",
  154. },
  155. S = {
  156. "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>",
  157. "Workspace Symbols",
  158. },
  159. },
  160. s = {
  161. name = "Search",
  162. b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" },
  163. c = { "<cmd>Telescope colorscheme<cr>", "Colorscheme" },
  164. f = { "<cmd>Telescope find_files<cr>", "Find File" },
  165. h = { "<cmd>Telescope help_tags<cr>", "Find Help" },
  166. M = { "<cmd>Telescope man_pages<cr>", "Man Pages" },
  167. r = { "<cmd>Telescope oldfiles<cr>", "Open Recent File" },
  168. R = { "<cmd>Telescope registers<cr>", "Registers" },
  169. t = { "<cmd>Telescope live_grep<cr>", "Text" },
  170. },
  171. T = {
  172. name = "Treesitter",
  173. i = { ":TSConfigInfo<cr>", "Info" },
  174. },
  175. }
  176. -- if O.plugin.trouble.active then
  177. -- mappings["d"] = {
  178. -- name = "Diagnostics",
  179. -- t = { "<cmd>TroubleToggle<cr>", "trouble" },
  180. -- w = { "<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace" },
  181. -- d = { "<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document" },
  182. -- q = { "<cmd>TroubleToggle quickfix<cr>", "quickfix" },
  183. -- l = { "<cmd>TroubleToggle loclist<cr>", "loclist" },
  184. -- r = { "<cmd>TroubleToggle lsp_references<cr>", "references" },
  185. -- }
  186. -- end
  187. if O.plugin.symbol_outline.active then
  188. vim.api.nvim_set_keymap("n", "<leader>o", ":SymbolsOutline<CR>", { noremap = true, silent = true })
  189. mappings["o"] = "Symbols outline"
  190. end
  191. if O.plugin.ts_playground.active then
  192. vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true })
  193. mappings[""] = "Highlight Capture"
  194. end
  195. if O.plugin.zen.active then
  196. vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true })
  197. mappings["z"] = "Zen"
  198. end
  199. if O.plugin.telescope_project.active then
  200. -- open projects
  201. vim.api.nvim_set_keymap(
  202. "n",
  203. "<leader>P",
  204. ":lua require'telescope'.extensions.project.project{}<CR>",
  205. { noremap = true, silent = true }
  206. )
  207. mappings["P"] = "Projects"
  208. end
  209. if O.lushmode then
  210. mappings["L"] = {
  211. name = "+Lush",
  212. l = { ":Lushify<cr>", "Lushify" },
  213. x = { ":lua require('lush').export_to_buffer(require('lush_theme.cool_name'))", "Lush Export" },
  214. t = { ":LushRunTutorial<cr>", "Lush Tutorial" },
  215. q = { ":LushRunQuickstart<cr>", "Lush Quickstart" },
  216. }
  217. end
  218. if O.plugin.floatterm then
  219. vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true })
  220. mappings["gg"] = "LazyGit"
  221. end
  222. for k, v in pairs(O.user_which_key) do
  223. mappings[k] = v
  224. end
  225. local wk = require "which-key"
  226. wk.register(mappings, opts)