which-key.vim 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. " Leader Key Maps
  2. let @s = 'veS"'
  3. " Timeout
  4. let g:which_key_timeout = 100
  5. let g:which_key_display_names = {'<CR>': '↵', '<TAB>': '⇆'}
  6. " Map leader to which_key
  7. nnoremap <silent> <leader> :silent <c-u> :silent WhichKey '<Space>'<CR>
  8. vnoremap <silent> <leader> :silent <c-u> :silent WhichKeyVisual '<Space>'<CR>
  9. " Create map to add keys to
  10. let g:which_key_map = {}
  11. " Define a separator
  12. let g:which_key_sep = '→'
  13. " set timeoutlen=100
  14. " Not a fan of floating windows for this
  15. let g:which_key_use_floating_win = 0
  16. let g:which_key_max_size = 0
  17. " let g:which_key_position = 'botright'
  18. " let g:which_key_position = 'topleft'
  19. " let g:which_key_vertical = 1
  20. " Change the colors if you want
  21. " Hide status line
  22. autocmd! FileType which_key
  23. autocmd FileType which_key set laststatus=0 noshowmode noruler
  24. \| autocmd BufLeave <buffer> set laststatus=2 noshowmode ruler
  25. " Single mappings
  26. let g:which_key_map['/'] = [ ':call Comment()' , 'comment' ]
  27. let g:which_key_map['?'] = [ ':NvimTreeFindFile' , 'comment' ]
  28. let g:which_key_map['.'] = [ ':e $MYVIMRC' , 'open init' ]
  29. let g:which_key_map[';'] = [ ':Commands' , 'commands' ]
  30. let g:which_key_map['='] = [ '<C-W>=' , 'balance windows' ]
  31. let g:which_key_map['e'] = [ ':NvimTreeToggle' , 'explorer' ]
  32. let g:which_key_map['h'] = [ '<C-W>s' , 'split below']
  33. let g:which_key_map['n'] = [ ':let @/ = ""' , 'no highlight' ]
  34. let g:which_key_map['o'] = [ ':RnvimrToggle' , 'open' ]
  35. let g:which_key_map['p'] = [ ':Files' , 'search files' ]
  36. " TODO fix this
  37. " let g:which_key_map['q'] = [ ':q' , 'quit' ]
  38. let g:which_key_map['T'] = [ ':TSHighlightCapturesUnderCursor' , 'treesitter highlight' ]
  39. let g:which_key_map['u'] = [ ':UndotreeToggle' , 'undo tree']
  40. let g:which_key_map['v'] = [ '<C-W>v' , 'split right']
  41. let g:which_key_map['W'] = [ ':call WindowSwap#EasyWindowSwap()' , 'move window' ]
  42. let g:which_key_map['z'] = [ 'Goyo' , 'zen' ]
  43. " Group mappings
  44. " a is for actions
  45. let g:which_key_map.a = {
  46. \ 'name' : '+actions' ,
  47. \ 'c' : [':ColorizerToggle' , 'colorizer'],
  48. \ 'e' : [':CocCommand explorer' , 'explorer'],
  49. \ 'h' : [':let @/ = ""' , 'remove search highlight'],
  50. \ 'l' : [':Bracey' , 'start live server'],
  51. \ 'L' : [':BraceyStop' , 'stop live server'],
  52. \ 'm' : [':MarkdownPreview' , 'markdown preview'],
  53. \ 'M' : [':MarkdownPreviewStop' , 'markdown preview stop'],
  54. \ 'n' : [':set nonumber!' , 'line-numbers'],
  55. \ 's' : [':s/\%V\(.*\)\%V/"\1"/' , 'surround'],
  56. \ 'r' : [':set norelativenumber!' , 'relative line nums'],
  57. \ 't' : [':FloatermToggle' , 'terminal'],
  58. \ 'v' : [':Codi' , 'virtual repl on'],
  59. \ 'V' : [':Codi!' , 'virtual repl off'],
  60. \ 'w' : [':StripWhitespace' , 'strip whitespace'],
  61. \ }
  62. " b is for buffer
  63. let g:which_key_map.b = {
  64. \ 'name' : '+buffer' ,
  65. \ '>' : [':BufferMoveNext' , 'move next'],
  66. \ '<' : [':BufferMovePrevious' , 'move prev'],
  67. \ '1' : [':BufferGoto 1' , 'buffer 1'],
  68. \ '2' : [':BufferGoto 2' , 'buffer 2'],
  69. \ '3' : [':BufferGoto 3' , 'buffer 3'],
  70. \ '4' : [':BufferGoto 4' , 'buffer 4'],
  71. \ '5' : [':BufferGoto 5' , 'buffer 5'],
  72. \ '6' : [':BufferGoto 6' , 'buffer 6'],
  73. \ '7' : [':BufferGoto 7' , 'buffer 7'],
  74. \ '8' : [':BufferGoto 8' , 'buffer 8'],
  75. \ '9' : [':BufferGoto 9' , 'buffer 9'],
  76. \ '0' : [':BufferGoto 0' , 'buffer 0'],
  77. \ 'b' : [':BufferPick' , 'pick buffer'],
  78. \ 'd' : [':Bdelete' , 'delete-buffer'],
  79. \ 'D' : [':BufferOrderByDirectory', 'order by directory'],
  80. \ 'f' : ['bfirst' , 'first-buffer'],
  81. \ 'l' : ['blast' , 'last buffer'],
  82. \ 'L' : [':BufferOrderByLanguage' , 'order by language'],
  83. \ 'n' : ['bnext' , 'next-buffer'],
  84. \ 'p' : ['bprevious' , 'previous-buffer'],
  85. \ '?' : ['Buffers' , 'fzf-buffer'],
  86. \ }
  87. " d is for debug
  88. let g:which_key_map.d = {
  89. \ 'name' : '+debug' ,
  90. \ 'b' : ['<Plug>VimspectorToggleBreakpoint' , 'breakpoint'],
  91. \ 'B' : ['<Plug>VimspectorToggleConditionalBreakpoint' , 'conditional breakpoint'],
  92. \ 'c' : ['<Plug>VimspectorRunToCursor' , 'run to cursor'],
  93. \ 'd' : ['<Plug>VimspectorContinue' , 'continue'],
  94. \ 'f' : ['<Plug>VimspectorAddFunctionBreakpoint' , 'function breakpoint'],
  95. \ 'm' : [':MaximizerToggle' , 'maximize window'],
  96. \ 'o' : ['<Plug>VimspectorStepOver' , 'step over'],
  97. \ 'O' : ['<Plug>VimspectorStepOut' , 'step out'],
  98. \ 'i' : ['<Plug>VimspectorStepInto' , 'step into'],
  99. \ 'p' : ['<Plug>VimspectorPause' , 'pause'],
  100. \ 'r' : ['<Plug>VimspectorRestart' , 'restart'],
  101. \ 's' : ['<Plug>VimspectorStop' , 'stop'],
  102. \ }
  103. " F is for fold
  104. let g:which_key_map.F = {
  105. \ 'name': '+fold',
  106. \ 'O' : [':set foldlevel=20', 'open all'],
  107. \ 'C' : [':set foldlevel=0', 'close all'],
  108. \ 'c' : [':foldclose', 'close'],
  109. \ 'o' : [':foldopen', 'open'],
  110. \ '1' : [':set foldlevel=1', 'level1'],
  111. \ '2' : [':set foldlevel=2', 'level2'],
  112. \ '3' : [':set foldlevel=3', 'level3'],
  113. \ '4' : [':set foldlevel=4', 'level4'],
  114. \ '5' : [':set foldlevel=5', 'level5'],
  115. \ '6' : [':set foldlevel=6', 'level6']
  116. \ }
  117. " f is for find and replace
  118. " \ 'f' : [':Farr' , 'file'],
  119. let g:which_key_map.f = {
  120. \ 'name' : '+find & replace' ,
  121. \ 'f' : [':Farr --source=vimgrep' , 'file'],
  122. \ 'p' : [':Farr --source=rgnvim' , 'project'],
  123. \ }
  124. " command! -buffer JdtCompile lua require('jdtls').compile()
  125. " command! -buffer JdtUpdateConfig lua require('jdtls').update_project_config()
  126. " command! -buffer JdtJol lua require('jdtls').jol()
  127. " command! -buffer JdtBytecode lua require('jdtls').javap()
  128. " command! -buffer JdtJshell lua require('jdtls').jshell()
  129. " j is for java
  130. let g:which_key_map.j = {
  131. \ 'name' : '+java' ,
  132. \ 'c' : [':AsyncTask file-compile' , 'compile file'],
  133. \ 'b' : [':AsyncTask project-build' , 'build project'],
  134. \ 'e' : [':AsyncTaskEdit' , 'edit local tasks'],
  135. \ 'f' : [':AsyncTaskFzf' , 'find task'],
  136. \ 'g' : [':AsyncTaskEdit!' , 'edit global tasks'],
  137. \ 'h' : [':AsyncTaskList!' , 'list hidden tasks'],
  138. \ 'l' : [':CocList tasks' , 'list tasks'],
  139. \ 'm' : [':AsyncTaskMacro' , 'macro help'],
  140. \ 'o' : [':copen' , 'open task view'],
  141. \ 'r' : [':AsyncTask file-run' , 'run file'],
  142. \ 'p' : [':AsyncTask project-run' , 'run project'],
  143. \ 'x' : [':cclose' , 'close task view'],
  144. \ }
  145. " k is for task
  146. let g:which_key_map.k = {
  147. \ 'name' : '+task' ,
  148. \ 'c' : [':AsyncTask file-compile' , 'compile file'],
  149. \ 'b' : [':AsyncTask project-build' , 'build project'],
  150. \ 'e' : [':AsyncTaskEdit' , 'edit local tasks'],
  151. \ 'f' : [':AsyncTaskFzf' , 'find task'],
  152. \ 'g' : [':AsyncTaskEdit!' , 'edit global tasks'],
  153. \ 'h' : [':AsyncTaskList!' , 'list hidden tasks'],
  154. \ 'm' : [':AsyncTaskMacro' , 'macro help'],
  155. \ 'o' : [':copen' , 'open task view'],
  156. \ 'r' : [':AsyncTask file-run' , 'run file'],
  157. \ 'p' : [':AsyncTask project-run' , 'run project'],
  158. \ 'x' : [':cclose' , 'close task view'],
  159. \ }
  160. " \ 'l' : [':AsyncTaskList' , 'list tasks'],
  161. " m is for mark
  162. let g:which_key_map.m = {
  163. \ 'name' : '+mark' ,
  164. \ 'c' : [':CocCommand bookmark.clearForCurrentFile', 'clear file'],
  165. \ 'C' : [':CocCommand bookmark.clearForAllFiles', 'clear project'],
  166. \ 'j' : [':CocCommand bookmark.next', 'next bookmark'],
  167. \ 'k' : [':CocCommand bookmark.prev', 'prev bookmark'],
  168. \ 't' : [':CocCommand bookmark.toggle', 'toggle bookmark'],
  169. \ }
  170. " CoC throws an error
  171. " \ 'a' : [':CocCommand bookmark.annotate', 'annotate bookmark'],
  172. " s is for search powered by telescope
  173. let g:which_key_map.s = {
  174. \ 'name' : '+search' ,
  175. \ '.' : [':Telescope filetypes' , 'filetypes'],
  176. \ ';' : [':Telescope commands' , 'commands'],
  177. \ 'a' : [':Telescope lsp_code_actions' , 'code_actions'],
  178. \ 'A' : [':Telescope builtin' , 'all'],
  179. \ 'b' : [':Telescope buffers' , 'buffers'],
  180. \ 'B' : [':Telescope git_branches' , 'git branches'],
  181. \ 'd' : [':Telescope lsp_document_diagnostics' , 'document_diagnostics'],
  182. \ 'D' : [':Telescope lsp_workspace_diagnostics' , 'workspace_diagnostics'],
  183. \ 'c' : [':Telescope git_commits' , 'git_commits'],
  184. \ 'C' : [':Telescope git_bcommits' , 'git_bcommits'],
  185. \ 'f' : [':Telescope find_files' , 'files'],
  186. \ 'F' : [':Telescope git_files' , 'git_files'],
  187. \ 'g' : [':Telescope tags' , 'tags'],
  188. \ 'G' : [':Telescope current_buffer_tags' , 'buffer_tags'],
  189. \ 'h' : [':Telescope command_history' , 'history'],
  190. \ 'H' : [':Telescope help_tags' , 'help_tags'],
  191. \ 'i' : [':Telescope media_files' , 'media files'],
  192. \ 'k' : [':Telescope keymaps' , 'keymaps'],
  193. \ 'l' : [':Telescope loclist' , 'loclist'],
  194. \ 'm' : [':Telescope marks' , 'marks'],
  195. \ 'M' : [':Telescope man_pages' , 'man_pages'],
  196. \ 'o' : [':Telescope vim_options' , 'vim_options'],
  197. \ 'O' : [':Telescope oldfiles' , 'oldfiles'],
  198. \ 'p' : [':Telescope fd' , 'fd'],
  199. \ 'P' : [':Telescope spell_suggest' , 'spell_suggest'],
  200. \ 's' : [':Telescope git_status' , 'git_status'],
  201. \ 'S' : [':Telescope grep_string' , 'grep_string'],
  202. \ 't' : [':Telescope live_grep' , 'text'],
  203. \ 'y' : [':Telescope symbols' , 'symbols'],
  204. \ 'Y' : [':Telescope lsp_workspace_symbols' , 'lsp_workspace_symbols'],
  205. \ 'r' : [':Telescope registers' , 'registers'],
  206. \ 'R' : [':Telescope reloader' , 'reloader'],
  207. \ 'w' : [':Telescope file_browser' , 'buf_fuz_find'],
  208. \ 'u' : [':Telescope colorscheme' , 'colorschemes'],
  209. \ 'z' : [':Telescope current_buffer_fuzzy_find' , 'buf_fuz_find'],
  210. \ }
  211. let g:which_key_map.S = {
  212. \ 'name' : '+Session' ,
  213. \ 'c' : [':SClose' , 'Close Session'] ,
  214. \ 'd' : [':SDelete' , 'Delete Session'] ,
  215. \ 'l' : [':SLoad' , 'Load Session'] ,
  216. \ 's' : [':Startify' , 'Start Page'] ,
  217. \ 'S' : [':SSave' , 'Save Session'] ,
  218. \ }
  219. " g is for git
  220. let g:which_key_map.g = {
  221. \ 'name' : '+git' ,
  222. \ 'a' : [':Git add .' , 'add all'],
  223. \ 'A' : [':CocCommand fzf-preview.GitStatus' , 'actions'],
  224. \ 'b' : [':Git blame' , 'blame'],
  225. \ 'B' : [':GBrowse' , 'browse'],
  226. \ 'c' : [':Git commit' , 'commit'],
  227. \ 'd' : [':Git diff' , 'diff'],
  228. \ 'D' : [':Gdiffsplit' , 'diff split'],
  229. \ 'g' : [':GGrep' , 'git grep'],
  230. \ 'G' : [':Gstatus' , 'status'],
  231. \ 'h' : [':GitGutterLineHighlightsToggle' , 'highlight hunks'],
  232. \ 'H' : ['<Plug>(GitGutterPreviewHunk)' , 'preview hunk'],
  233. \ 'i' : [':Gist -b' , 'post gist'],
  234. \ 'j' : ['<Plug>(GitGutterNextHunk)' , 'next hunk'],
  235. \ 'k' : ['<Plug>(GitGutterPrevHunk)' , 'prev hunk'],
  236. \ 'l' : [':Git log' , 'log'],
  237. \ 'm' : ['<Plug>(git-messenger)' , 'message'],
  238. \ 'p' : [':Git push' , 'push'],
  239. \ 'P' : [':Git pull' , 'pull'],
  240. \ 'r' : [':GRemove' , 'remove'],
  241. \ 's' : ['<Plug>(GitGutterStageHunk)' , 'stage hunk'],
  242. \ 'S' : [':CocCommand fzf-preview.GitStatus' , 'status'],
  243. \ 't' : [':GitGutterSignsToggle' , 'toggle signs'],
  244. \ 'u' : ['<Plug>(GitGutterUndoHunk)' , 'undo hunk'],
  245. \ 'v' : [':GV' , 'view commits'],
  246. \ 'V' : [':GV!' , 'view buffer commits'],
  247. \ }
  248. " \ 'A' : [':Git add %' , 'add current'],
  249. " \ 'S' : [':!git status' , 'status'],
  250. let g:which_key_map.G = {
  251. \ 'name' : '+gist' ,
  252. \ 'a' : [':Gist -a' , 'post gist anon'],
  253. \ 'b' : [':Gist -b' , 'post gist browser'],
  254. \ 'd' : [':Gist -d' , 'delete gist'],
  255. \ 'e' : [':Gist -e' , 'edit gist'],
  256. \ 'l' : [':Gist -l' , 'list public gists'],
  257. \ 's' : [':Gist -ls' , 'list starred gists'],
  258. \ 'm' : [':Gist -m' , 'post gist all buffers'],
  259. \ 'p' : [':Gist -P' , 'post public gist '],
  260. \ 'P' : [':Gist -p' , 'post private gist '],
  261. \ }
  262. " l is for language server protocol
  263. let g:which_key_map.l = {
  264. \ 'name' : '+lsp' ,
  265. \ 'a' : [':Lspsaga code_action' , 'quickfix'],
  266. \ 'A' : [':Lspsaga range_code_action' , 'selected action'],
  267. \ 'd' : [':Telescope lsp_document_diagnostics' , 'document diagnostics'],
  268. \ 'D' : [':Telescope lsp_workspace_diagnostics', 'workspace diagnostics'],
  269. \ 'f' : [':LspFormatting' , 'format'],
  270. \ 'H' : [':Lspsaga signature_help' , 'signature_help'],
  271. \ 'I' : [':LspInfo' , 'lsp_info'],
  272. \ 'l' : [':Lspsaga lsp_finder' , 'lsp_finder'],
  273. \ 'L' : [':Lspsaga show_line_diagnostics' , 'line_diagnostics'],
  274. \ 'o' : [':Vista!!' , 'outline'],
  275. \ 'p' : [':Lspsaga preview_definition' , 'preview definition'],
  276. \ 'q' : [':Telescope quickfix' , 'quickfix'],
  277. \ 'r' : [':LspRename' , 'rename'],
  278. \ 'T' : [':LspTypeDefinition' , 'type defintion'],
  279. \ 'x' : [':cclose' , 'close quickfix'],
  280. \ 's' : [':Telescope lsp_document_symbols' , 'document symbols'],
  281. \ 'S' : [':Telescope lsp_workspace_symbols' , 'workspace symbols'],
  282. \ }
  283. " \ 'D' : [':LspDeclaration' , 'workspace_diagnostics'],
  284. " \ 'r' : [':Telescope lsp_references' , 'references'],
  285. " \ 'p' : [':Lspsaga diagnostic_jump_prev' , 'prev diagnostic'],
  286. " \ 'n' : [':Lspsaga diagnostic_jump_next' , 'next_diagnostic'],
  287. " \ 'q' : [':Lspsaga code_action' , 'quickfix'],
  288. " \ 'i' : [':LspImplementation' , 'lsp_info'],
  289. " \ 'h' : [':Lspsaga hover_doc' , 'hover_doc'],
  290. " \ 'K' : [':LspHover' , 'hover'],
  291. " t is for terminal
  292. let g:which_key_map.t = {
  293. \ 'name' : '+terminal' ,
  294. \ ';' : [':FloatermNew --wintype=normal --height=6' , 'terminal'],
  295. \ 'f' : [':FloatermNew fzf' , 'fzf'],
  296. \ 'g' : [':FloatermNew lazygit' , 'git'],
  297. \ 'd' : [':FloatermNew lazydocker' , 'docker'],
  298. \ 'n' : [':FloatermNew node' , 'node'],
  299. \ 'N' : [':FloatermNew nnn' , 'nnn'],
  300. \ 'p' : [':FloatermNew python' , 'python'],
  301. \ 'm' : [':FloatermNew lazynpm' , 'npm'],
  302. \ 'r' : [':FloatermNew ranger' , 'ranger'],
  303. \ 't' : [':FloatermToggle' , 'toggle'],
  304. \ 'y' : [':FloatermNew ytop' , 'ytop'],
  305. \ 'u' : [':FloatermNew ncdu' , 'ncdu'],
  306. \ }
  307. call which_key#register('<Space>', "g:which_key_map")