init.lua 12 KB

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