" =======================================================
" 基于已经存在的快捷键映射,直接使用一个字符串说明介绍信息即可
" =======================================================
" You can pass a descriptive text to an existing mapping.
let g:which_key_map.f = { 'name' : '+file' }
nnoremap fs :update
let g:which_key_map.f.s = 'save-file'
nnoremap fd :e $MYVIMRC
let g:which_key_map.f.d = 'open-vimrc'
call which_key#register('', "g:which_key_map")
这个函数,在打开gvim的时候会出现如图所示的错误。但是打开后在手动运行这个函数可以。
以下是代码: Plug 'liuchengxu/vim-which-key' set timeoutlen=500 let g:mapleader = "\"
let g:maplocalleader = ','
" nnoremap :WhichKey ''
" nnoremap :WhichKey ','
let g:which_key_map = {}
"
name
是一个特殊字段,如果 dict 里面的元素也是一个 dict,那么表明一个 group,比如+file
, 就会高亮和显示+file
。默认是+prefix
." ======================================================= " 基于已经存在的快捷键映射,直接使用一个字符串说明介绍信息即可 " ======================================================= " You can pass a descriptive text to an existing mapping.
let g:which_key_map.f = { 'name' : '+file' }
nnoremap fs :update
let g:which_key_map.f.s = 'save-file'
nnoremap fd :e $MYVIMRC
let g:which_key_map.f.d = 'open-vimrc'
nnoremap oq :copen
nnoremap ol :lopen
let g:which_key_map.o = { \ 'name' : '+open', \ 'q' : 'open-quickfix' , \ 'l' : 'open-locationlist', \ } " ======================================================= " 不存在相关的快捷键映射,需要用一个 list: " 第一个元素表明执行的操作,第二个是该操作的介绍 " ======================================================= " Provide commands(ex-command,// mapping, etc.) and descriptions for existing mappings
let g:which_key_map.b = {
\ 'name' : '+buffer' ,
\ '1' : ['b1' , 'buffer 1'] ,
\ '2' : ['b2' , 'buffer 2'] ,
\ 'd' : ['bd' , 'delete-buffer'] ,
\ 'f' : ['bfirst' , 'first-buffer'] ,
\ 'h' : ['Startify' , 'home-buffer'] ,
\ 'l' : ['blast' , 'last-buffer'] ,
\ 'n' : ['bnext' , 'next-buffer'] ,
\ 'p' : ['bprevious' , 'previous-buffer'] ,
\ }
call which_key#register('', "g:which_key_map")
nnoremap :WhichKey ''
vnoremap :WhichKeyVisual ''