1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-19 18:33:43 +08:00
SpaceVim/autoload/SpaceVim/mapping/frequency.vim
2023-03-26 13:44:47 +08:00

40 lines
1.1 KiB
VimL

"=============================================================================
" frequency.vim --- key frequency plugin
" Copyright (c) 2016-2023 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
let s:data = {}
function! SpaceVim#mapping#frequency#update(key, rhs) abort
if has_key(s:data, a:key)
let s:data[a:key] += 1
else
let s:data[a:key] = 1
endif
return a:rhs
endfunction
function! SpaceVim#mapping#frequency#view(keys) abort
if type(a:keys) == 1
echo 'The frequency of ' . a:keys . ' is ' . s:get(a:keys)
elseif type(a:keys) == 3
for key in a:keys
call SpaceVim#mapping#frequency#view(key)
endfor
endif
endfunction
function! SpaceVim#mapping#frequency#viewall() abort
echo string(s:data)
endfunction
function! s:get(key) abort
if has_key(s:data, a:key)
return s:data[a:key]
else
return 0
endif
endfunction