init.lua 10 KB

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