init.lua 9.4 KB

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