init.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 = {"<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
  34. show_help = true -- show help message on the command line when the popup is visible
  35. }
  36. local opts = {
  37. mode = "n", -- NORMAL mode
  38. prefix = "<leader>",
  39. buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  40. silent = true, -- use `silent` when creating keymaps
  41. noremap = true, -- use `noremap` when creating keymaps
  42. nowait = false -- use `nowait` when creating keymaps
  43. }
  44. -- no hl
  45. vim.api.nvim_set_keymap('n', '<Leader>h', ':let @/=""<CR>', {noremap = true, silent = true})
  46. -- explorer
  47. vim.api.nvim_set_keymap('n', '<Leader>e', ":lua require'lv-nvimtree'.toggle_tree()<CR>", {noremap = true, silent = true})
  48. -- telescope
  49. vim.api.nvim_set_keymap('n', '<Leader>f', ':Telescope find_files<CR>', {noremap = true, silent = true})
  50. -- dashboard
  51. vim.api.nvim_set_keymap('n', '<Leader>;', ':Dashboard<CR>', {noremap = true, silent = true})
  52. -- Comments
  53. vim.api.nvim_set_keymap("n", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true})
  54. vim.api.nvim_set_keymap("v", "<leader>/", ":CommentToggle<CR>", {noremap = true, silent = true})
  55. -- close buffer
  56. vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>", {noremap = true, silent = true})
  57. -- open projects
  58. vim.api.nvim_set_keymap('n', '<leader>p', ":lua require'telescope'.extensions.project.project{}<CR>",
  59. {noremap = true, silent = true})
  60. -- TODO create entire treesitter section
  61. local mappings = {
  62. ["/"] = "Comment",
  63. ["c"] = "Close Buffer",
  64. ["e"] = "Explorer",
  65. ["f"] = "Find File",
  66. ["h"] = "No Highlight",
  67. ["p"] = "Projects",
  68. b = {
  69. name = "+Buffers",
  70. j = {"<cmd>BufferPick<cr>", "jump to buffer"},
  71. w = {"<cmd>BufferWipeout<cr>", "wipeout buffer"},
  72. e = {"<cmd>BufferCloseAllButCurrent<cr>", "close all but current buffer"},
  73. h = {"<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left"},
  74. l = {"<cmd>BufferCloseBuffersRight<cr>", "close all BufferLines to the right"},
  75. D = {"<cmd>BufferOrderByDirectory<cr>", "sort BufferLines automatically by directory"},
  76. L = {"<cmd>BufferOrderByLanguage<cr>", "sort BufferLines automatically by language"},
  77. },
  78. -- ["/"] = {"<cmd>CommentToggle<cr>", "Comment"},
  79. [";"] = {"<cmd>Dashboard<cr>", "Dashboard"},
  80. -- ["c"] = {"<cmd>BufferClose<cr>", "Close Buffer"},
  81. -- ["e"] = {"<cmd>NvimTreeToggle<cr>", "Explorer"},
  82. -- ["f"] = {"<cmd>Telescope find_files<cr>", "Find File"},
  83. -- ["h"] = {"<cmd>set hlsearch!<cr>", "No Highlight"},
  84. -- ["p"] = {"<cmd>lua require'telescope'.extensions.project.project{}<cr>", "Projects"},
  85. d = {
  86. name = "Diagnostics",
  87. t = {"<cmd>TroubleToggle<cr>", "trouble"},
  88. w = {"<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace"},
  89. d = {"<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document"},
  90. q = {"<cmd>TroubleToggle quickfix<cr>", "quickfix"},
  91. l = {"<cmd>TroubleToggle loclist<cr>", "loclist"},
  92. r = {"<cmd>TroubleToggle lsp_references<cr>", "references"}
  93. },
  94. D = {
  95. name = "Debug",
  96. b = {"<cmd>DebugToggleBreakpoint<cr>", "Toggle Breakpoint"},
  97. c = {"<cmd>DebugContinue<cr>", "Continue"},
  98. i = {"<cmd>DebugStepInto<cr>", "Step Into"},
  99. o = {"<cmd>DebugStepOver<cr>", "Step Over"},
  100. r = {"<cmd>DebugToggleRepl<cr>", "Toggle Repl"},
  101. s = {"<cmd>DebugStart<cr>", "Start"}
  102. },
  103. g = {
  104. name = "Git",
  105. j = {"<cmd>NextHunk<cr>", "Next Hunk"},
  106. k = {"<cmd>PrevHunk<cr>", "Prev Hunk"},
  107. p = {"<cmd>PreviewHunk<cr>", "Preview Hunk"},
  108. r = {"<cmd>ResetHunk<cr>", "Reset Hunk"},
  109. R = {"<cmd>ResetBuffer<cr>", "Reset Buffer"},
  110. s = {"<cmd>StageHunk<cr>", "Stage Hunk"},
  111. u = {"<cmd>UndoStageHunk<cr>", "Undo Stage Hunk"},
  112. o = {"<cmd>Telescope git_status<cr>", "Open changed file"},
  113. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  114. c = {"<cmd>Telescope git_commits<cr>", "Checkout commit"},
  115. C = {"<cmd>Telescope git_bcommits<cr>", "Checkout commit(for current file)"}
  116. },
  117. l = {
  118. name = "LSP",
  119. a = {"<cmd>Lspsaga code_action<cr>", "Code Action"},
  120. A = {"<cmd>Lspsaga range_code_action<cr>", "Selected Action"},
  121. d = {"<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics"},
  122. D = {"<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics"},
  123. f = {"<cmd>LspFormatting<cr>", "Format"},
  124. h = {"<cmd>Lspsaga hover_doc<cr>", "Hover Doc"},
  125. i = {"<cmd>LspInfo<cr>", "Info"},
  126. l = {"<cmd>Lspsaga lsp_finder<cr>", "LSP Finder"},
  127. L = {"<cmd>Lspsaga show_line_diagnostics<cr>", "Line Diagnostics"},
  128. p = {"<cmd>Lspsaga preview_definition<cr>", "Preview Definition"},
  129. q = {"<cmd>Telescope quickfix<cr>", "Quickfix"},
  130. r = {"<cmd>Lspsaga rename<cr>", "Rename"},
  131. t = {"<cmd>LspTypeDefinition<cr>", "Type Definition"},
  132. x = {"<cmd>cclose<cr>", "Close Quickfix"},
  133. s = {"<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols"},
  134. S = {"<cmd>Telescope lsp_dynamic_workspace_symbols<cr>", "Workspace Symbols"}
  135. },
  136. r = {
  137. name = "Replace",
  138. f = {"<cmd>lua require('spectre').open_file_search()<cr>", "Current File"},
  139. p = {"<cmd>lua require('spectre').open()<cr>", "Project"}
  140. },
  141. s = {
  142. name = "Search",
  143. b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
  144. c = {"<cmd>Telescope colorscheme<cr>", "Colorscheme"},
  145. d = {"<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics"},
  146. D = {"<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics"},
  147. f = {"<cmd>Telescope find_files<cr>", "Find File"},
  148. h = {"<cmd>Telescope help_tags<cr>", "Find Help"},
  149. m = {"<cmd>Telescope marks<cr>", "Marks"},
  150. M = {"<cmd>Telescope man_pages<cr>", "Man Pages"},
  151. r = {"<cmd>Telescope oldfiles<cr>", "Open Recent File"},
  152. R = {"<cmd>Telescope registers<cr>", "Registers"},
  153. t = {"<cmd>Telescope live_grep<cr>", "Text"}
  154. },
  155. S = {
  156. name = "Session",
  157. s = {"<cmd>SessionSave<cr>", "Save Session"},
  158. l = {"<cmd>SessionLoad<cr>", "Load Session"}
  159. },
  160. -- extras
  161. z = {
  162. name = "Zen",
  163. s = {"<cmd>TZBottom<cr>", "toggle status line"},
  164. t = {"<cmd>TZTop<cr>", "toggle tab bar"},
  165. z = {"<cmd>TZAtaraxis<cr>", "toggle zen"}
  166. }
  167. }
  168. if O.extras then
  169. mappings["L"] = {
  170. name = "+Latex",
  171. c = {"<cmd>VimtexCompile<cr>", "Toggle Compilation Mode"},
  172. f = {"<cmd>call vimtex#fzf#run()<cr>", "Fzf Find"},
  173. i = {"<cmd>VimtexInfo<cr>", "Project Information"},
  174. s = {"<cmd>VimtexStop<cr>", "Stop Project Compilation"},
  175. t = {"<cmd>VimtexTocToggle<cr>", "Toggle Table Of Content"},
  176. v = {"<cmd>VimtexView<cr>", "View PDF"}
  177. }
  178. end
  179. -- TODO come back and fix visual mappings
  180. -- local visualOpts = {
  181. -- mode = "v", -- Visual mode
  182. -- prefix = "<leader>",
  183. -- buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
  184. -- silent = true, -- use `silent` when creating keymaps
  185. -- noremap = true, -- use `noremap` when creating keymaps
  186. -- nowait = false -- use `nowait` when creating keymaps
  187. -- }
  188. -- local visualMappings = {
  189. -- ["/"] = {"<cmd>CommentToggle<cr>", "Comment"},
  190. -- r = {
  191. -- name = "Replace",
  192. -- f = {"<cmd>lua require('spectre').open_visual({path = vim.fn.expand('%')})<cr>", "File"},
  193. -- p = {"<cmd>lua require('spectre').open_visual()<cr>", "Project"}
  194. -- }
  195. -- }
  196. local wk = require("which-key")
  197. wk.register(mappings, opts)
  198. -- wk.register(visualMappings, visualOpts)