init.lua 12 KB

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