which-key.vim 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. " Map leader to which_key
  2. nnoremap <silent> <leader> :silent WhichKey '<Space>'<CR>
  3. vnoremap <silent> <leader> :silent <c-u> :silent WhichKeyVisual '<Space>'<CR>
  4. " Create map to add keys to
  5. let g:which_key_map = {}
  6. " Define a separator
  7. let g:which_key_sep = '→'
  8. " set timeoutlen=100
  9. " Not a fan of floating windows for this
  10. let g:which_key_use_floating_win = 0
  11. " Change the colors if you want
  12. highlight default link WhichKey Operator
  13. highlight default link WhichKeySeperator DiffAdded
  14. highlight default link WhichKeyGroup Identifier
  15. highlight default link WhichKeyDesc Function
  16. " Hide status line
  17. autocmd! FileType which_key
  18. autocmd FileType which_key set laststatus=0 noshowmode noruler
  19. \| autocmd BufLeave <buffer> set laststatus=2 noshowmode ruler
  20. " Single mappings
  21. let g:which_key_map['/'] = [ '<Plug>NERDCommenterToggle' , 'comment' ]
  22. let g:which_key_map['.'] = [ ':e $MYVIMRC' , 'open init' ]
  23. let g:which_key_map[';'] = [ ':Commands' , 'commands' ]
  24. let g:which_key_map['='] = [ '<C-W>=' , 'balance windows' ]
  25. let g:which_key_map['d'] = [ ':bd' , 'delete buffer']
  26. let g:which_key_map['e'] = [ ':CocCommand explorer' , 'explorer' ]
  27. let g:which_key_map['f'] = [ ':Files' , 'search files' ]
  28. let g:which_key_map['h'] = [ '<C-W>s' , 'split below']
  29. let g:which_key_map['q'] = [ 'q' , 'quit' ]
  30. let g:which_key_map['r'] = [ ':Ranger' , 'ranger' ]
  31. let g:which_key_map['S'] = [ ':Startify' , 'start screen' ]
  32. let g:which_key_map['T'] = [ ':Rg' , 'search text' ]
  33. let g:which_key_map['v'] = [ '<C-W>v' , 'split right']
  34. let g:which_key_map['w'] = [ 'w' , 'write' ]
  35. let g:which_key_map['z'] = [ 'Goyo' , 'zen' ]
  36. " Group mappings
  37. " b is for buffer
  38. let g:which_key_map.b = {
  39. \ 'name' : '+buffer' ,
  40. \ '1' : ['b1' , 'buffer 1'] ,
  41. \ '2' : ['b2' , 'buffer 2'] ,
  42. \ 'd' : ['bd' , 'delete-buffer'] ,
  43. \ 'f' : ['bfirst' , 'first-buffer'] ,
  44. \ 'h' : ['Startify' , 'home-buffer'] ,
  45. \ 'l' : ['blast' , 'last-buffer'] ,
  46. \ 'n' : ['bnext' , 'next-buffer'] ,
  47. \ 'p' : ['bprevious' , 'previous-buffer'] ,
  48. \ '?' : ['Buffers' , 'fzf-buffer'] ,
  49. \ }
  50. " s is for search
  51. let g:which_key_map.s = {
  52. \ 'name' : '+search' ,
  53. \ '/' : [':History/' , 'history'],
  54. \ ';' : [':Commands' , 'commands'],
  55. \ 'a' : [':Ag' , 'text Ag'],
  56. \ 'b' : [':BLines' , 'current buffer'],
  57. \ 'B' : [':Buffers' , 'open buffers'],
  58. \ 'c' : [':Commits' , 'commits'],
  59. \ 'C' : [':BCommits' , 'buffer commits'],
  60. \ 'f' : [':Files' , 'files'],
  61. \ 'g' : [':GFiles' , 'git files'],
  62. \ 'G' : [':GFiles?' , 'modified git files'],
  63. \ 'h' : [':History' , 'file history'],
  64. \ 'H' : [':History:' , 'command history'],
  65. \ 'l' : [':Lines' , 'lines'] ,
  66. \ 'm' : [':Marks' , 'marks'] ,
  67. \ 'M' : [':Maps' , 'normal maps'] ,
  68. \ 'p' : [':Helptags' , 'help tags'] ,
  69. \ 'P' : [':Tags' , 'project tags'],
  70. \ 's' : [':Snippets' , 'snippets'],
  71. \ 'S' : [':Colors' , 'color schemes'],
  72. \ 't' : [':Rg' , 'text Rg'],
  73. \ 'T' : [':BTags' , 'buffer tags'],
  74. \ 'w' : [':Windows' , 'search windows'],
  75. \ 'y' : [':Filetypes' , 'file types'],
  76. \ 'z' : [':FZF' , 'FZF'],
  77. \ }
  78. " g is for git
  79. let g:which_key_map.g = {
  80. \ 'name' : '+git' ,
  81. \ 'a' : [':Git add .' , 'add all'],
  82. \ 'A' : [':Git add %' , 'add current'],
  83. \ 'b' : [':Git blame' , 'blame'],
  84. \ 'B' : [':GBrowse' , 'browse'],
  85. \ 'c' : [':Git commit -m "autocommit"' , 'commit'],
  86. \ 'd' : [':Git diff' , 'diff'],
  87. \ 'D' : [':Gdiffsplit' , 'diff split'],
  88. \ 'g' : [':GGrep' , 'git grep'],
  89. \ 'G' : [':Gstatus' , 'status'],
  90. \ 'h' : [':GitGutterLineHighlightsToggle' , 'highlight hunks'],
  91. \ 'H' : ['<Plug>(GitGutterPreviewHunk)' , 'preview hunk'],
  92. \ 'j' : ['<Plug>(GitGutterNextHunk)' , 'next hunk'],
  93. \ 'k' : ['<Plug>(GitGutterPrevHunk)' , 'prev hunk'],
  94. \ 'l' : [':Git log' , 'log'],
  95. \ 'p' : [':Git push' , 'push'],
  96. \ 'P' : [':Git pull' , 'pull'],
  97. \ 'r' : [':GRemove' , 'remove'],
  98. \ 's' : ['<Plug>(GitGutterStageHunk)' , 'stage hunk'],
  99. \ 't' : [':GitGutterSignsToggle' , 'toggle signs'],
  100. \ 'u' : ['<Plug>(GitGutterUndoHunk)' , 'undo hunk'],
  101. \ 'v' : [':GV' , 'view commits'],
  102. \ 'V' : [':GV!' , 'view buffer commits'],
  103. \ }
  104. " l is for language server protocol
  105. let g:which_key_map.l = {
  106. \ 'name' : '+lsp' ,
  107. \ '.' : [':CocConfig' , 'config'],
  108. \ ';' : ['<Plug>(coc-refactor)' , 'refactor'],
  109. \ 'a' : ['<Plug>(coc-codeaction)' , 'line action'],
  110. \ 'A' : ['<Plug>(coc-codeaction-selected)' , 'selected action'],
  111. \ 'b' : [':CocNext' , 'next action'],
  112. \ 'B' : [':CocPrev' , 'prev action'],
  113. \ 'c' : [':CocList commands' , 'commands'],
  114. \ 'd' : ['<Plug>(coc-definition)' , 'definition'],
  115. \ 'D' : ['<Plug>(coc-declaration)' , 'declaration'],
  116. \ 'e' : [':CocList extensions' , 'extensions'],
  117. \ 'f' : ['<Plug>(coc-format-selected)' , 'format selected'],
  118. \ 'F' : ['<Plug>(coc-format)' , 'format'],
  119. \ 'h' : ['<Plug>(coc-float-hide)' , 'hide'],
  120. \ 'i' : ['<Plug>(coc-implementation)' , 'implementation'],
  121. \ 'I' : [':CocList diagnostics' , 'diagnostics'],
  122. \ 'j' : ['<Plug>(coc-float-jump)' , 'float jump'],
  123. \ 'l' : ['<Plug>(coc-codelens-action)' , 'code lens'],
  124. \ 'n' : ['<Plug>(coc-diagnostic-next)' , 'next diagnostic'],
  125. \ 'N' : ['<Plug>(coc-diagnostic-next-error)' , 'next error'],
  126. \ 'o' : ['<Plug>(coc-openlink)' , 'open link'],
  127. \ 'O' : [':CocList outline' , 'outline'],
  128. \ 'p' : ['<Plug>(coc-diagnostic-prev)' , 'prev diagnostic'],
  129. \ 'P' : ['<Plug>(coc-diagnostic-prev-error)' , 'prev error'],
  130. \ 'q' : ['<Plug>(coc-fix-current)' , 'quickfix'],
  131. \ 'r' : ['<Plug>(coc-rename)' , 'rename'],
  132. \ 'R' : ['<Plug>(coc-references)' , 'references'],
  133. \ 's' : [':CocList -I symbols' , 'references'],
  134. \ 't' : ['<Plug>(coc-type-definition)' , 'type definition'],
  135. \ 'u' : [':CocListResume' , 'resume list'],
  136. \ 'U' : [':CocUpdate' , 'update CoC'],
  137. \ 'v' : [':Vista!!' , 'tag viewer'],
  138. \ 'z' : [':CocDisable' , 'disable CoC'],
  139. \ 'Z' : [':CocEnable' , 'enable CoC'],
  140. \ }
  141. " t is for toggle
  142. let g:which_key_map.t = {
  143. \ 'name' : '+toggle' ,
  144. \ 'c' : [':ColorizerToggle' , 'colorizer'],
  145. \ 'e' : [':CocCommand explorer' , 'explorer'],
  146. \ 'n' : [':set nonumber!' , 'line-numbers'],
  147. \ 'r' : [':set norelativenumber!' , 'relative line nums'],
  148. \ 's' : [':let @/ = ""' , 'remove search highlight'],
  149. \ 't' : [':FloatermToggle' , 'terminal'],
  150. \ 'v' : [':Vista!!' , 'tag viewer'],
  151. \ }
  152. " Register which key map
  153. call which_key#register('<Space>', "g:which_key_map")